Reputation: 10482
I have set up ASP.NET MVC 4 with System.Web.Providers, and now I would like to add some more user information, like address, birthdate, etc.
I would also like to relate the existing user data from Providers to post, such that each post has an author from the Providers.
I must be such that when a user creates a post, everything about the user must be (lazily) available from selecting that post.
I was maybe thinking about having a User class containing the UserProfile
class from the standard MVC template project (which seems to be used with the HTTP login), and the aspnet_users
from the providers, but I am not really sure how to go about this.
What is the common way of doing this?
Upvotes: 1
Views: 430
Reputation: 9271
This link should give you all the info to implement your ProfileProvider
As suggested in the post (they go with the third option) and also in this answer, you should consider implementing your own logic to bind the profile to the currently active user
I use a profile class and extend the MembershipUser'one to implement my class. In that way I can access it with something like that:
var user = Membership.GetUser();
var profile = user.Profile;
Upvotes: 1
Reputation: 123861
I would suggest to go with Providers
. These are available in ASP.NET for a very long time, and still used. Their implementation is the same for both (WebForms and MVC) so I would suggest to read this comprehensive tutorial about them
The Profile
feature is exactly the place for user specific information. It can be extended easily and represents the extension point to Membership
. We are using our one Profile
class:
public class ProjectProfile : ProfileBase
{
// TODO custom properties
}
configured in web.config
<profile defaultProvider="ProjectProfile"
inherits="MyLibrary.ProjectProfile, MyLibrary">
<providers >
<clear/>
<add name="ProjectProfile" type="MyLibrary.ProjectProfileProvider, MyLibrary" />
</providers>
</profile>
So, the System.Web.HttpContext.Current.Profile as ProjectProfile
has the information needed.
Upvotes: 1