MVC 2 区域身份验证不起作用
使用 MVC 2,如果我使用表单身份验证设置我的根 web.config(没有位置部分),并且我转到区域之外的页面(远离根),我会像人们所期望的那样被重定向到登录页面。但是,如果我转到某个区域中的页面,我不会按预期重定向。我是否需要在该区域的某个地方添加一个额外的 web.config,或者我是否可能配置错误?
另外,我一定会清除所有 cookie 并从新的会话和浏览器开始,以防上次登录时出现问题。
我真的不想维护位置或多个 web.config 文件,因为整个网站都需要身份验证。
如果有帮助的话,我正在使用 Visual Studio 2010 并从 MVC 2 模板开始。
警告:我今天早上只喝了 2 杯咖啡,所以可能是椅子和键盘之间短路...
谢谢,
--Patrick
Using MVC 2, if I setup my root web.config with forms authentication (there is no locations section), and I go to a page outside an area (off of the root), I get redirected to the login page as one would expect. However, if I go to a page in an area, I don't get redirected as expected. Do I need an additional web.config somewhere in the area or do I possibly have something mis-configured?
Also, I have been sure to clear all cookies and start from a new session and browser just in case something was holding over from a previous login.
I really did not want to have to maintain locations or multiple web.config files since the whole site needs authentication.
If it helps, I am using Visual Studio 2010 and started with a MVC 2 template.
Warning: I have only had 2 cups of coffee this morning so it could be a short circuit between the chair and the keyboard...
Thanks,
--Patrick
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Web.config 授权不应与 MVC 应用程序一起使用。相反,请将 [Authorize] 属性应用于您想要保护的控制器。如果站点范围内的所有控制器都需要授权,请考虑使用具有 [Authorize] 属性的 BaseController,并使站点范围内的所有控制器都成为 BaseController 的子类。
Web.config authorization should not be used with an MVC application. Instead, apply the [Authorize] attribute to the controllers you wish to protect. If all of your controllers site-wide need authorization, consider having a BaseController with an [Authorize] attribute and having all of your controllers site-wide subclass the BaseController.