RoleProvider 的 IsUserInRole 方法的语法是:
public abstract bool IsUserInRole(
string username,
string roleName
)
因此,在覆盖时,您不能包含第三个参数。
为什么不定义自己的自定义方法说(额外的'S'):
IsUserInRoles(string username, string roleName1, string roleName2)
或者更好的方法:
IsUserInRoles(string username, string[] roles)
身体会是:
protected bool IsUserInRoles(string username, string[] rolenames)
{
if (username == null || username == "")
throw exception;
if (rolenames == null || rolenames.Length==0)
throw exception;
//code to check if user exists in all roles
// you can call even the default IsUserInRole() method one by one for all roles
bool userInRoles=true;
foreach (string role in roles )
{
if( !UserIsInRole(role))
// set the boolean value to false
userInRoles = false;
}
return userInRoles;
}