我的角色提供:C#角色多個供應商傾斜通話功能
<roleManager enabled="true" cacheRolesInCookie="true" cookieName=".ASPROLES" defaultProvider="AspNetSqlRoleProvider">
<providers>
<clear/>
<add connectionStringName="ConnectionString1" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider,System.Web, Version=2.0.0.0, Culture=neutral,PublicKeyToken=xxx"/>
<add connectionStringName="ConnectionString2" applicationName="/" name="AspNetSqlRoleProviderProduction" type="System.Web.Security.SqlRoleProvider,System.Web, Version=2.0.0.0, Culture=neutral,PublicKeyToken=xxx"/>
</providers>
</roleManager>
當我嘗試調用AddUserToRole:
var roleProviderProduction = Roles.Providers["AspNetSqlRoleProviderProduction"];
roleProviderProduction.AddUserToRole(username, role);
我得到這個錯誤:
Error 59 'System.Web.Security.RoleProvider' does not contain a definition for 'AddUserToRole' and no extension method 'AddUserToRole' accepting a first argument of type 'System.Web.Security.RoleProvider' could be found (are you missing a using directive or an assembly reference?)
不叫'AddUsersToRoles'的方法? – wkl
否:https://msdn.microsoft.com/en-us/library/system.web.security.roles.addusertorole%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396 – atroul
您正在混淆[RoleProvider](https://msdn.microsoft.com/en-us/library/system.web.security.roleprovider(v = vs.110).aspx)和[Roles](https://msdn.microsoft。 COM/EN-US /庫/ system.web.security.roles(v = vs.110)的.aspx)。請參閱下面的答案。 – wkl