Using roles in Asp.Net MemeberShip?

Deadly 提交于 2020-01-05 03:51:06

问题


Well, the question is simple.

how can i use the roles in asp.net memebership,

i know i can do something like that :

<authorization>
<allow roles="Admin"/> //Allows users in Admin role

<deny users="*"/> // deny everyone else
</authorization>

</system.web>
</location>

but, where can i say user 'admin' is Role : Admin..?


回答1:


It is just a tip of the ice berg. You need ASP.Net Membership and Role Providers, and configure few settings. You can implement your own providers, but it is easier to use the default ones.

http://www.codeproject.com/KB/aspnet/SQL-Membership.aspx

http://odetocode.com/articles/427.aspx

<system.web>

    <membership>
        <providers>
            <remove name="AspNetSqlMembershipProvider"/>
            <add applicationName="YOURAPPNAME" name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ASPNETDBConnectionString" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" requiresUniqueEmail="true" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="1" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>
        </providers>
    </membership>
    <roleManager enabled="true" cacheRolesInCookie="false">
        <providers>
            <remove name="AspNetSqlRoleProvider"/>
            <add applicationName="YOURAPPNAME" connectionStringName="ASPNETDBConnectionString" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
        </providers>
    </roleManager>

</system.web>



回答2:


You need to have RoleProvider http://msdn.microsoft.com/en-us/library/8fw7xh74.aspx

If you are using Windows Authentication, the roles will be your AD groups.

If you are using Form Authentication, you can implement your own RoleProvider or use SQL Role Provider.

http://msdn.microsoft.com/en-us/library/system.web.security.sqlroleprovider.aspx



来源:https://stackoverflow.com/questions/6526239/using-roles-in-asp-net-memebership

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!