views:

39

answers:

2

I am trying to make an asp.net website using Visual web dev and C# that accesses data in an SQL database. For my site, I need to be able to save and access additional user properties such as age and gender. I have been playing around with the built in .NET Login tools but I don't understand how to keep track of the additional properties (age, gender...) I could store all the users information in my own database but how do I correlate the users data in my DB to the usernames in the member database that is automatically created?

+1  A: 

Probably profiles are perfect and quite easy to use for your purpose. ASP.NET manages the relation between users and their associated profile data (which you can customize for your needs) quite comfortable. Here is short introduction video:

http://www.asp.net/learn/videos/video-44.aspx

Are you using an ASP.NET website project or web application project? The video (and most information in MSDN) is related to website projects. For web applications there are some complications to take into account when you use profiles.

(Some hints if you are using a web application project:

http://stackoverflow.com/questions/426609/asp-net-membership-how-to-assign-profile-values

If you are using an website project you can ignore this)

Slauma
+1, but to be honest, I've never found ASP.Net Profiles useful. I use the rest of the Membership API in just about every app I build though.
kervin
Hm, but how would you implement the requirement of the OP (storing age, gender, etc. per user)? Creating your own custom table for that purpose seems like inventing the wheel a second time. Well, perhaps except you'd like to build queries on those additional data (select all users between age of 20 and 30, for instance), which might be difficult, if not impossible, with the ASP.NET profiles because all the profile properties are stored in a large binary field.
Slauma
Right. And I use LINQ/EF, so running queries off the user table(s) is trivial. Also not that as your app groups you may need to store user profile info that has a 1:many relationship with the user, etc. So you still end up needing separate user tables in that case.
kervin
+1  A: 

As Slauma said ASP.Net Profiles is a great way to do this using the Membership API.

But I don't like the way profiles use delimited list serialized in the database, and I've heard reports of speed issues under heavy load.

I Use Membership API on just about all applications, except for the profile bit.

To store user profiles, you can create a separate table. Maybe called 'UserProfile'. Add a column with a unique index for 'username' and/or 'email'. Which ever you treat as the user's username. Now you can use that column to pull profile information at runtime.

As a bonus, if you use an ORM like Entity framework, you can now write simple LINQ queries to pull your user information.

kervin
OK, I'd like to comment that this answer to the question answers my question in the comment to my answer ;)
Slauma
This sounds like exactly what I need to do...
Jordan S
With this approach is it still possible to use the built in login tools or do you have to create your own?
Jordan S
Yes, you use the builtin controls as normal. The only part you're not using is the profile, that's all. But login, loginview, password recovery, etc. and all the membership APIs all work of the same ASP.Net membership provider. Check out the '4guysfromrolla' link in my post. It goes through membership well.
kervin