c#角色多个提供者无法调用函数
c# roles multiple providers cant call function
我的角色提供者:
<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?)
你搞混了RoleProvider and Roles. While there is a method AddUserToRole in Roles
, RoleProvider
only has AddUsersToRoles。
你应该使用
var roleProviderProduction = Roles.Providers["AspNetSqlRoleProviderProduction"];
roleProviderProduction.AddUsersToRoles(new string[]{username}, new string[]{role});
或
Roles.AddUserToRole(username, role);
我的角色提供者:
<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?)
你搞混了RoleProvider and Roles. While there is a method AddUserToRole in Roles
, RoleProvider
only has AddUsersToRoles。
你应该使用
var roleProviderProduction = Roles.Providers["AspNetSqlRoleProviderProduction"];
roleProviderProduction.AddUsersToRoles(new string[]{username}, new string[]{role});
或
Roles.AddUserToRole(username, role);