PDA

Click to See Complete Forum and Search --> : [RESOLVED] Membership and Roles (Custom Providers)


Pino
Oct 15th, 2009, 09:56 AM
I;ve posted this here because I dont really care what lanaguage. It could be VB or C# its the logic of what we are trying to do I wasnt to discuss.

We have a requirment to develop a system which has a Custom User object of which each user can have many log-ins (Active Directory, Open Id, Standard Login, Facebook Connect etc etc)

We have begun work on a custom Role/Membership provider which involves changing some of the method signatures. So for example, our role-provider


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


The standard sig for this method is


public override string[] GetRolesForUser(string username)


Obviously the whole idea of writing custom membership providers is so we can use the existing security and functions.

So when I call


Roles.GetRolesForUser()


I would like to see the option to pass a Int as well as a string. At the moment that is not the case unless we cast the object to be our provider.


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


Which to me seems to defeat the purpose of what we are doing? Does anyone have any experiance of really heavily customising the Roles/Membership provider?

I understand why we need to cast the object but I dont think its what we were hoping to acheive.

And if the above way of doing things isnt going to work as we want is our only other option to create a Complete custom Membership class.

Suggestions welcome.

DeanMc
Oct 15th, 2009, 04:41 PM
Ok, I may have this extremely wrong. I am presuming that you have an existing class that has functionality that is built and tested but only takes a string at the moment since they originally only had one set of credentials now they have multiple ones and you wish to extend this fact.

If I am correct well then extension methods would be an option. Now I don't claim to know em's very well but the principle seems to be that you create a static class with methods in it that mimic your original methods, IE injecting functionality without upsetting the base code.

I am assuming since your code contains the var keyword your using at least 3.0 which em's are a part of. Here is a link that explains how they function: http://blogs.msdn.com/ericwhite/pages/Extension-Methods.aspx

If I am wrong about this sorry but from what I gather I think this is what your looking for.

Pino
Oct 16th, 2009, 04:30 AM
Thanks Dean,

Its not really no, I think we are trying to put a round toy in a square box.

I think looking at it, we are going to have to conform a little more.

Cheers for the reply though.

DeanMc
Oct 16th, 2009, 05:30 AM
ah ok, sorry I thought it was a simple case of mimicing the existing funtionalty with a new method. I never worked with production code before so I thought I may have been off the mark alright, sorry.

gep13
Oct 22nd, 2009, 01:27 AM
Hey Pino,

I know you have marked your thread as resolved, but I thought you might be interested in the following thread in the ASP.Net Forum:

http://www.vbforums.com/showthread.php?t=579602

It doesn't answer your question directly, but it does show the combination of multiple login sources, which you seemed to be hinting at as well.

Hope it sheds some light for you.

Gary