views:

318

answers:

3

I am trying to implement a custom membership provider and want to change the GetUser method. The problem is that GetUser returns MembershipUser and I want to return MyMembershipUser which has two additional properties FirstName and LastName. I can create a new method in my membership provider which returns MyMembershipUser but then I think it won't make any sense.

How would I go about doing this?

+4  A: 

That would defeat the purpose of the Membership classes. Do something like this if you need to access other properties:

var user = Membership.GetUser(userName, true) as MyMembershipUser;

Really you should have a separate Profile class that handles things that MembershipUser does not provide.

var profile = Profile.GetProfile(Membership.GetUser(userName, true));
ChaosPandion
Thanks! seems like I can only accept yr answer in 4 minutes. I will wait!
john doe
Thanks I will use profile for that scenario! U THE MAN! :D
john doe
@john - Glad to be of assistance, good luck.
ChaosPandion
@John, i am not implying that this is not a correct answer, as it is, but it is not the only solution. The throttle on acceptance time is for your benefit. The longer you leave an answer open, the better chance you have of collecting quality responses. Upvotes are a good mechanism for indicating pleasure with an answer while waiting for other possibilities. Personally, I usually only check questions that have no accepted answer unless I am coming up short with interesting questions. Just saying that rushing acceptance is not expected and is generally against everyone's best interests...
Sky Sanders
+1 for what I consider the correct answer.
Sky Sanders
I agree @Sky Sanders and apologies for any trouble! I will keep that in mind!
john doe
@john, nothing to apologize for, just lookin out for you. Welcome to StackOverflow.
Sky Sanders
A: 

If MembershipUser is the base class of MyMembershipUser then you can return instances of MyMembershipUser even though the return type of GetUser() is MembershipUser and then, if necessary, cast them back to MyMembershipUser (but do you really need to do that?)

BTW, this is an example of polymorphism.

Daniel Renshaw
+1  A: 

You should go for Profile Provider. check this link, you have either SqlStoredProcedureProfileProvider and SqlTableProfileProvider, this way you have ability to store Profile data “in the clear” in the database, letting you query the db whenever u want.

"you can implement whatever business logic you need in the stored procedures to map the Profile data to your own database schema and database logic."

Rui Santos