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;
}