Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.net MVC 3 user accounts & profiles

I would like to add user accounts to my MVC 3 web app.For each user account I would like to add a corresponding user profile, with the usual email and address contact info, etc. Also maybe add some security questions for when the user forgets there login credentials.

I’ve read some info about using the provided ASP.net profile options and also some people suggest using your own membership tables as it quicker retrieveing user profile info especially when the user list grows.

Can anyone give me some insight on which approach to use and also point me in the direction of a any tutorials showing me how to implement User accounts and profiles within an MVC 3 Web Application?

Many thanks D

like image 973
davey Avatar asked May 04 '11 02:05

davey


2 Answers

If you aren't going to be querying these tables outside of what is built in for profiles, stick with the default out of the box roles/profile. Its a bit of additional work, troubleshooting, and development for custom profiles. Its not that its hard.. its just additional work. If you don't have a specific need to it use what is built in. As for performance, look at what you'll be running on. Do you have to squeeze out every bit of performance from the hardware you are running on? Most places do not, and have multiple sites on servers barely touching the disk and cpu, in that case (as is fairly typical) you are fine with everything built in.

To implement the accounts, create a new mvc3 project and in visual studio in the solution explorer click on the last icon on the right up top for "asp.net configuration" and manage

There are however many tutorials out there on implementing custom table providers in asp.net and they DO apply just as much to mvc since mvc is just an asp.net app.

like image 128
Adam Tuliper Avatar answered Sep 30 '22 07:09

Adam Tuliper


ProfileBase is the class you should look at.

Some sample code copied from one of my web site:

var profile = ProfileBase.Create(model.UserName);
profile.SetPropertyValue("Identity.FirstName",model.FirstName);
profile.SetPropertyValue("Identity.LastName", model.LastName);
profile.SetPropertyValue("Identity.FullName", model.FullName);
profile.SetPropertyValue("Contact.Email", model.Email);
profile.SetPropertyValue("Contact.Phone", model.PhoneNumber);
profile.Save(); 

Hope it is useful to you.

like image 38
Blaise Avatar answered Sep 30 '22 08:09

Blaise