views:

310

answers:

2

Edit: By Overriding the RoleProvider we were hoping to still use the same methods with our new methods. Such as Roles.GetRolesForUser(int).

 string[] myRoles3 = ((PortalRoleProvider) (Roles.Provider)).GetRolesForUser(2);

That above code seems a bit excessive ?

I have a class which overrides some members of the RoleProvider and adds new methods. Eg.

 public string[] GetRolesForUser(int UserId)
    {
        IEnumerable<Role> RoleList = _Repo.GetRolesForUser(UserId);


        string[] RetVal = new string[] {};

        foreach (var curRole in RoleList)
        {
            RetVal[RetVal.GetUpperBound(0)] = curRole.RoleName;
        }
        return RetVal;
    }

Now when I am in the logic of my code I want to write Roles.GetRolesForUser(2) but when i type this, it does seem to see the extra method that I have added. Here is the class declaration and the webconfig.

 namespace PortalMVC.Providers
 {
    public class PortalRoleProvider : RoleProvider
    {

Web.config

<roleManager enabled="true" defaultProvider="PortalRoleProvider">
    <providers>
        <clear/>
         <add name="PortalRoleProvider" type="PortalMVC.Providers.PortalRoleProvider"/>
    </providers>
</roleManager>

Any suggestions why this is?

+1  A: 

In the web.config, where you specify the type for the role provider, you might need to add the name of the assembly where the type can be found. Something like this:

<add name="PortalRoleProvider" type="PortalMVC.Providers.PortalRoleProvider, MyAssemblyName" />
Matt Hamsmith
I've done this, but this hasnt helped with the above issue. Thanks though.
Pino
+2  A: 
Kendrick
Ok this makes sense, can you expand? If I wanted to call the GetRolesForUser(int a) how would I do that?
Pino
"string[] myRoles = new PortalRoleProvider().GetRolesForUser(2);" this seems a bit backwards though since we only want to expand on the current RoleProvider.
Pino
Better yet, use interfaces to decouple the objects.
Yuriy Faktorovich