简体   繁体   中英

C# ASP.Net WebForm Membership Extra User Details (Profile)

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?

您可能必须首先使用Membership.CreateUser创建MembershipUser,获取新创建的用户ID,然后在单独的表(如ExtendedUserInfo等)中插入其额外的配置文件信息,并使用forein键将其与aspnet_Users表链接。

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM