views:

122

answers:

1

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");
        if (username.Equals("Dave"))
            roles.Add("Admin");
        return roles.ToArray();
    }
 }
 }

From this error, it seems like it can't find the RoleProvider. Any ideas?

+1  A: 

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

MUG4N
Oh boy, that was it. I don't know how long I spent staring at that code without even realizing I'd typed 'class' instead of 'namespace'. Thanks!
Ethan
I am glad that I could help you ... shit happenz
MUG4N