MVC在主目录中的web.config里配置区域内的指定目录只有指定的角色可以访问时有效果,但是如果我在区域内指定的目录下加一个web.config文件在里面设置角色授权如下:
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.web> <authorization> <allow roles="admin"/> <deny users="*"/> </authorization> </system.web> </configuration>
则没有效果,这是什么情况导致的,我仍然可以访问,请问各位大大咋整?
这个应该结合asp.net 的 membership这些来实现的
我的配置文件一般这么写:
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="ApplicationServices"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="5"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider"
type="System.Web.Profile.SqlProfileProvider"
connectionStringName="ApplicationServices"
applicationName="/" />
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider"
type="System.Web.Security.SqlRoleProvider"
connectionStringName="ApplicationServices"
applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider"
type="System.Web.Security.WindowsTokenRoleProvider"
applicationName="/" />
</providers>
</roleManager>
如果要自动生成权限和角色表 还需要安装:aspnet_regsql.exe
默认路径在这:C:\Windows\Microsoft.NET\Framework\v4.0.30319
<allow roles="admin"/> <deny users="*"/>
顺序反过来试试
访问MVC的cshtml视图 对应目录的Web.config的角色权限配置根本不起作用,但是如果加一个aspx页面进去 就起作用
@Sicket: 通过area来控制吧