如何从FilterAttribute中获取当前的网址? [英] How do I get the current Url from within a FilterAttribute?
本文介绍了如何从FilterAttribute中获取当前的网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个Authorize过滤器属性,但在弄清楚如何将当前网址作为字符串获取时遇到了麻烦,因此我可以将其作为参数传递给LogOn操作。目的是如果用户成功登录,他们将被重定向到他们最初尝试访问的页面。
I am writing an Authorize filter attribute adn I'm having trouble figuring out how to get the current url as a string so I can pass it as a parameter to the LogOn action. The goal is that if a user successfully logs on, they will be redirected to the page they were originally trying to access.
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
How do I get the full string Url from the current request?
推荐答案
尝试:
var url = filterContext.HttpContext.Request.Url;
这篇关于如何从FilterAttribute中获取当前的网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文