<location>属性</location> </authorization> </authentication>中的MVC3 <authentication>和<authorization>

时间:2012-04-03 17:51:46

标签: visual-studio-2010 asp.net-mvc-3 forms-authentication

我是.NET和MVC3的新手,我目前正在将一个长期的经典ASP网站转换为MVC3应用程序网站。

同一个网站有四个区域,我需要独特的登录页面和离散的访问级别和安全性。这意味着我不想在我的web.config文件中使用默认代码:

<authentication mode="Forms">
  <forms loginUrl="~/Account/Logon" timeout="2880" />
</authentication>

相反,我希望能够在我的应用程序内部设置区域,然后使用<location>属性为每个区域设置身份验证和授权规则。例如:

<location path="AreaName">
 <system.web>
  <authentication mode="Forms">
    <forms loginUrl="~/AreaName/Login" timeout="15" />
  </authentication>
  <authorization>
    <deny users="?"/>
  </authorization>
 </system.web>
</location>

如果删除这三行:

  <authentication mode="Forms">
    <forms loginUrl="~/AreaName/Login" timeout="15" />
  </authentication>

然后当我尝试访问路径“AreaName”中的任何视图时,我首先被重定向回〜/ Account / LogOn。如果我重新放入这三行,我会收到以下错误:

  

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

我搜索过这个错误,并没有提出任何建议似乎适用。我已经看到一个答案,其中逻辑应放在控制器而不是Web配置中,但这些方法仍然暗示您将使用默认<authentication>整个站点。

我不明白为什么我不能在<authentication>内部拥有<location>属性。对此的任何帮助都将非常感激。

如果我错误地说出了这个问题,我很抱歉。

1 个答案:

答案 0 :(得分:0)

您可能需要自定义成员资格提供程序和自定义角色提供程序(如果需要)...这是一个示例帖子Custom membership providers in ASP.NET ...如果您的关注点是访问级别,则需要使用自定义角色提供者......