我正在开发Asp.Net MVC 3应用程序.我已经为网站创建了管理区域,并在登录后将[授权]属性应用于actionmethods.当我尝试直接访问这些URL而无需像admin / home或admin / productlist那样登录时,我被重定向到/ Home / Login并出现身份验证错误.我想重定向到管理员/登录.
请建议.
谢谢
解决方法
ASP.NET应用程序(包括MVC3)的登录URL在web.config中控制,在表单身份验证部分中:
<configuration> <system.web> <authentication mode="Forms"> <forms loginUrl="~/Home/Login" timeout="2880" /> </authentication> </system.web> </configuration>
你的诀窍是你需要两个不同的登录URL. ASP.NET有一个很棒的功能,你可以在项目的每个目录中都有一个web.config文件,并且根据需要,它将使用它可以找到的最具体的设置,直到根web.config.因此,在您拥有管理员视图的文件夹中(我猜是“管理员”),您应该能够创建第二个web.config,它将仅应用于树中的那些页面和更低的页面:
<configuration> <system.web> <authentication mode="Forms"> <forms loginUrl="~/Admin/Login" timeout="2880" /> </authentication> </system.web> </configuration>