开发者

Access User details in membership of Asp.Net MVC application

I am using the default membership authorization that is created when you start a new project in VS for MVC 3. When a user is registered (either if I do it for them in the Administration page or if they register themselves through the Register page created in the application), there is an email field for instance. But where is this stored? Shouldn't I be able to access that e-mail somehow? I can't find it in the User object...

Also, is it possible to add more fields when they register, and 开发者_JAVA技巧to access those as well? For instance address, phone number, etc?


1. Getting the e-mail

You can access the property from the current user by using the Membership object.

 Membership.GetUser().Email

2. Extra Fields

The best way to add more fields to the register process is to make another model called UserDetail or something. And make a relationship between User and UserDetail.

Or you throw away the default membership authorization and make a custom one. Here are some handy links:

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

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

http://www.15seconds.com/issue/050216.htm

http://davidhayden.com/blog/dave/archive/2007/10/11/CreateCustomMembershipProviderASPNETWebsiteSecurity.aspx


For the extra user fields you can use the ASP.NET profile provider. here is a good article about how to implement it: http://ashuthinks.wordpress.com/2012/01/08/asp-net-mvc-profile-provider/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜