在asp.net mvc的上HttpUnauthorizedResult默认登录网址 [英] default login url on HttpUnauthorizedResult in asp.net mvc
问题描述
我写了一个自定义的 AuthorizeAttribute
这在asp.net MVC3应用以下条件:
I have written a custom AuthorizeAttribute
which has the following condition in asp.net mvc3 application:
public override void OnAuthorization(AuthorizationContext filterContext)
{
//auth failed, redirect to Sign In
if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
{
filterContext.Result = new HttpUnauthorizedResult();
}
}
和在我的web.config,我有:
And in my web.config, i have:
<authentication mode="Forms">
<forms loginUrl="~/User/SignIn" timeout="2880" />
</authentication>
在验证失败,默认情况下它重定向到/帐号/登录页面。
On authentication fail, it redirects to "/Account/Login" page by default.
如何更改此默认重定向URL,并重定向到/用户/签到?
How do i change this default redirect url and redirect it to "/User/SignIn"?
的截图显示的正是我想说的..
The screenshot shows the clear view of what i am trying to say..
虽然我已经设置/用户/签到,它重定向到/帐号/登录
Though i have set '/User/SignIn', it redirects to '/Account/Login'
推荐答案
我不知道我是否可以添加这是一个答案。但是,这可能会帮助谁是有这个相关的问题等。
I am not sure whether i can add this as an answer. But this may help others who were having this related issue.
我有一个斗争后的溶液。我最近已经添加WebMatrix.WebData参考,这似乎是这个问题的真正元凶。这可以通过将关键看你的配置文件的处理方式:
I got the solution after a struggle. I have added WebMatrix.WebData reference recently, which seems to be the real culprit of this issue. This can be handled by adding the key to your config file:
<add key="loginUrl" value="~/User/SignIn" />
这篇关于在asp.net mvc的上HttpUnauthorizedResult默认登录网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!