我写一个授权过滤器属性我没有找到如何获取当前的URL作为字符串,所以我可以将其作为参数传递给logon操作。目标是如果用户成功登录,他们将被重定向到他们最初尝试访问的页面。
public override void OnAuthorization(AuthorizeContext filterContext) { base.OnAuthorization(filterContext); ... my auth code ... bool isAuth ; ... my auth code ... if(!isAuth) { filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary { { "Area","" },{ "Controller","Account" },{ "Action","logon" },{ "RedirectUrl","/Url/String/For/Currnt/Request" } // how do I get this? } ); } }
如何从当前请求中获取完整字符串Url?
解决方法
尝试:
var url = filterContext.HttpContext.Request.Url;