ASP.NET MVC 3区域和web.config中的多重身份验证

eye*_*snz 13 authentication asp.net-mvc-3-areas asp.net-mvc-3

我一直在尝试关注此博客以使区域运作:

http://mstechkb.blogspot.com/2010/10/areas-in-aspnet-mvc-20.html

在博客文章中,它标识了为每个区域设置身份验证的能力,例如:

<location path="Area1">
  <system.web>
  <authentication mode="Windows" />
  <authorization> 
    <allow roles="role1,role2"/>
    <deny users="*"/> 
  </authorization> 
</system.web>
</location>
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试在Visual Studio 2010中的新项目中创建它时,运行时出现以下错误:

在应用程序级别之外使用注册为allowDefinition ='MachineToApplication'的部分是错误的.此错误可能是由于未在IIS中将虚拟目录配置为应用程序引起的.

从我可以看到这是因为你不能指定一个身份验证元素,除非它在顶级web.config中.

那么博客文章可以做什么呢?您是否可以在web.config中的Location元素中包含具有Authentication元素的区域?

Mar*_*und -2

根据我对 ASP.NET MVC 的了解,最好将 [Authorization] 属性应用于各个控制器来设置授权规则,因为考虑到路由系统的工作方式,它更安全、更充分。