开发者

ASP.NET custom RoleProvider error

开发者 https://www.devze.com 2022-12-30 00:35 出处:网络
I\'m trying to use this article to learn about custom roleproviders, but I\'m getting this error: Could not load type \'TestRoles.SimpleRoleProvider\'.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消