我寫這在asp.net MVC3應用以下條件的自定義AuthorizeAttribute
:默認登錄網址
public override void OnAuthorization(AuthorizationContext filterContext)
{
//auth failed, redirect to Sign In
if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
{
filterContext.Result = new HttpUnauthorizedResult();
}
}
而且在我的web.config,我有:
<authentication mode="Forms">
<forms loginUrl="~/User/SignIn" timeout="2880" />
</authentication>
驗證失敗後,默認情況下,它會重定向到「/帳戶/登錄」頁面。
如何更改此默認重定向網址並將其重定向到「/用戶/登錄」?
的截圖顯示的就是我想說的清晰視野..
雖然我已經設置「/用戶/簽到」,它重定向到「/帳號/登錄」
? – 2011-05-17 13:18:47
是的。我正在使用MVC3。 – Prasad 2011-05-17 13:29:55
經過一番努力,我獲得瞭解決方案。我最近添加了WebMatrix.WebData參考,這似乎是這個問題的真正罪魁禍首。這可以通過將密鑰添加到您的配置文件來處理: –
Prasad
2011-05-20 08:57:33