views:

34

answers:

3

In my master page I have:

MembershipUser thisUser = Membership.GetUser();
loggedInUserID = thisUser.ProviderUserKey.ToString();

thisUser gives me access to all the fields in aspnet_Membership.

I want a new field, isSubscribed for each user. I can use an SQL query to fetch the value fine, but I want to know if there is someway to modify the membershipuser object so it retrieves this value as well, so it is accessible from:

thisUser.isSubscribed.ToString();

Thanks for any help!

+1  A: 

you will need to add the field to the Profile Provider

A description of the Profile provider can be found here.

http://msdn.microsoft.com/en-us/library/2y3fs9xs.aspx

here is an excerpt from the article

"The ASP.NET profile feature associates information with an individual user and stores the information in a persistent format. Profiles allow you to manage user information without requiring you to create and maintain your own database. In addition, the ASP.NET profile feature makes the user information available using a strongly typed API that you can access from anywhere in your application."

Si Robinson
Super thanks, am using profile provider now
Tom Gullen
A: 

Si Robinson gave a good answer for storing additional meta data against users without having to change the underlying schema but if you already have data stored about this user in your custom database schema, that won't quite work out.

The solution I have used is to implement my own membership provider:

http://msdn.microsoft.com/en-us/library/f1kyba5e.aspx

And then you can implement your own MembershipUser which exposes the IsSubscribed property.

This works fine with the Membership process within ASP.NET such as the login components. All you need to do is cast the object returned by GetUser() to your custom implementation and you are set!

Neil Trodden
+1  A: 

Membership is for identification and authentication. It is not good practice to hack your security for the sake of a meta property.

As mentioned, Profile is the proper place to store meta data and this would obviate the need for a custom MembershipUser.

If you need sql query access to the data use the SqlTableProvider

Sky Sanders