我寫了一個授權篩選器屬性adn我無法弄清楚如何將當前url作爲字符串獲取,因此我可以將它作爲參數傳遞給LogOn操作。目標是如果用戶成功登錄,他們將被重定向到他們最初嘗試訪問的頁面。如何從FilterAttribute中獲取當前Url?
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?
你也可以使用RawUrl(filterContext.HttpContext.Request.RawUrl)來獲得沒有域的url –