Reputation: 579
I'm learning how to use the ASP.net membership, when a user registers they just create a username and password, however i want to create a page on my website called "profile" where they can fill in extra details such as firstname, lastname, date of birth ect. However i don't see where i can place this in the asp.net membership database. Theres an asp.net_profile table however i'm not sure how this works.
Could someone please explain how i can do this?
Upvotes: 4
Views: 944
Reputation: 15673
You should treat the built-in membership stuff as a black box -- extending the stock membership schema is a pretty bad idea in general.
The profiles is pretty ugly to be honest -- kind if handy for storing miscellaneous settings but I would hate to store data I cared about extracting at some point. The main issue is it stores stuff in an an opaque serialized field so it is hard to extract your data. Overhead can be nasty as it will deserialize this stuff on every request, so if you have an extensive profile it can get expensive. And it isn't worth pulling out someone's extra profile info every request in most cases.
As for usage, I'd start with the MSDN page. Also note that there are additional challenges in MVC -- it is not wired into that stack as directly, though one can still make use of it.
All that said, you probably want to build out your own member profile table of some sort here. You probably will double-book some data with the built-in membership bits but that is OK. You will want to setup this table with some sort of relationship to the membership -- I prefer using an "owner account id" structure rather than keying it directly to accounts as that makes things much more flexible. For example, it lets users have multiple profiles if that becomes necessary.
Upvotes: 4
Reputation: 1186
So as you have already configured the membership and roles section, you do the same with the profile section. But here you can provide properties like:
<profile defaultProvider="AspNetSqlProfileProvider">
<properties>
<add name="Name" />
<add name="Weight" type="System.Int32" />
<add name="BirthDate"
type="System.DateTime" />
</properties>
</profile>
In your code you can call Profile.Name and assign a value, the ASP.Membership framework manages storing the values.
More information about how to use it are on http://msdn.microsoft.com/en-us/library/d8b58y5d(v=vs.100).aspx it's a bit old but shows the basics.
Upvotes: 2
Reputation: 2750
You will probably have to create MembershipUser first by using Membership.CreateUser, grab the newly created user's id and then insert his extra profile information in seperate table (like ExtendedUserInfo etc) and link that with aspnet_Users table with forein key.
Upvotes: 4