如果没有登录,则重定向到使用 AuthorizeWebForm 属性登录
If not login then redirect to Login with AuthorizeWebForm attribute
我有一个带有 [AuthorizeWebForm] 属性的控制器。
现在,如果我没有登录但我想访问那个页面,那么它会给我
HTTP Error 401.0 - Unauthorized.
You do not have permission to view this directory or page.
现在,我该如何使用 [AuthorizeWebForm] 属性来处理这个问题?如果我没有登录并尝试访问该页面,那么它应该重定向到登录页面。
我找到了解决方案。我只是将下面的代码放入 web.config。会话已在自定义错误 class 中检查过。如果会话为空,则重定向到登录页面。
<authentication mode="Forms">
<forms name=".SomeLoginCookie" loginUrl="~/Account/Login" timeout="2880" protection="All" enableCrossAppRedirects="true" />
</authentication>
我有一个带有 [AuthorizeWebForm] 属性的控制器。
现在,如果我没有登录但我想访问那个页面,那么它会给我
HTTP Error 401.0 - Unauthorized. You do not have permission to view this directory or page.
现在,我该如何使用 [AuthorizeWebForm] 属性来处理这个问题?如果我没有登录并尝试访问该页面,那么它应该重定向到登录页面。
我找到了解决方案。我只是将下面的代码放入 web.config。会话已在自定义错误 class 中检查过。如果会话为空,则重定向到登录页面。
<authentication mode="Forms">
<forms name=".SomeLoginCookie" loginUrl="~/Account/Login" timeout="2880" protection="All" enableCrossAppRedirects="true" />
</authentication>