ASP.NET custom RoleProvider error
I'm trying to use this article to learn about custom roleproviders, but I'm getting this error:
Could not load type 'TestRoles.SimpleRoleProvider'.
The relevant section from my web.config:
<roleManager enabled="true" defaultProvider="SimpleRoleProvider">
<providers>
<add name="SimpleRoleProvider" type="TestRoles.SimpleRoleProvider"/>
</providers>
</roleManager>
The RolesProvider.cs class:
public class TestRoles{
public class SimpleRoleProvider : RoleProvider
{
public override string[] GetRolesForUser(string username)
{
List<string> roles = new List<string>();
roles.Add("Guest");
开发者_JS百科 if (username.Equals("Dave"))
roles.Add("Admin");
return roles.ToArray();
}
}
}
From this error, it seems like it can't find the RoleProvider. Any ideas?
Well it seems to me that your namespace is wrong:
TestRoles.SimpleRoleProvider
Your namespace must me TestRoles and your class name SimpleRoleProvider
Change your class TestRoles to namespace and make sure that you don't have any other namespace above TestRoles like xy.TestRoles.SimpleRoleProvider
精彩评论