How to I add more custom fields using custom membership in mvc?

You need to implement Custom Membership User. Here is a sample implementation.

Up vote 1 down vote favorite 1 share g+ share fb share tw.

I have override the memship methods to create an custom membership. In account model override the method create user public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, password, true); OnValidatingPassword(args); if (args. Cancel) { status = MembershipCreateStatus.

InvalidPassword; return null; } if (RequiresUniqueEmail && GetUserNameByEmail(email)! = "") { status = MembershipCreateStatus. DuplicateEmail; return null; } MembershipUser you = GetUser(username, false); if (u == null) { UserRepository _user = new UserRepository(); //here it is called my new method which has fileds from User table i'm using entity framework.

_user. CreateUser(username, password, email); status = MembershipCreateStatus. Success; return GetUser(username, false); } else { status = MembershipCreateStatus.

DuplicateUserName; } return null; } public MembershipUser CreateUser(string username, string password, string email) { using (CustomMembershipDB db = new CustomMembershipDB()) { User user = new User(); user. UserName = username; user. Email = email; user.

PasswordSalt = CreateSalt(); user. Password = CreatePasswordHash(password, user. PasswordSalt); user.

CreatedDate = DateTime. Now; user. IsActivated = false; user.

IsLockedOut = false; user. LastLockedOutDate = DateTime. Now; user.

LastLoginDate = DateTime. Now; //Generate an email key // user. NewEmailKey = GenerateKey(); db.

AddToUsers(user); db.SaveChanges(); //send mail // SendMail(user); return GetUser(username); } } Now here I need to add more two fields like first name and last name but how can I pass it to above method? As it is override Membership CreateUser method it will give me an error if I took some parameters like firstname and last name into it :( asp.net asp.net-mvc asp.net-mvc-3 asp.net-mvc-2 membership-provider link|improve this question edited Jan 6 at 17:40danludwig4,8452522 asked Jan 6 at 15:31ashuthinks561114 83% accept rate.

You really shouldn't try to add fields to the MembershipUser class. If you want to store FirstName, LastName, etc, the Profile & ProfileProvider ('' in web. Config) was designed for this.

– danludwig Jan 6 at 17:38 how can I use that please give me any link? – ashuthinks Jan 6 at 17:42 here is your link: google.com? Q=asp.

Net+profile+provider – danludwig Jan 6 at 17:49 i'm using mvc :( – ashuthinks Jan 7 at 4:05 You can use ProfileProvider in MVC, just as you can use MembershipProvider and RoleProvider. Profiles are ASP. NET, not WebForms.

– danludwig Jan 7 at 4:38.

You need to implement Custom Membership User. Here is a sample implementation: msdn.microsoft.com/en-us/library/ms36673... Also take a look at this thread: Implement Custom MembershipUser and Custom MembershipProvider Implementing Custom MembershipUser.

Make a class that inherits from MembershipProvider and implement methods that are identical by just calling the SqlMembershipProvider but change others that you want a different Functionality. Take a look at this article SQLite 3.0 Membership and Role Provider for ASP. NET 2.0 UPDATE: The Membership system in ASP.

NET was designed to create a standardized API for working with user accounts, a task faced by many web applications (refer back to Part 1 of this article series for a more in-depth look at Membership). While the Membership system encompasses core user-related properties - username, password, email address, and so on - oftentimes additional information needs to be captured for each user. Unfortunately, this additional information can differ wildly from application to application.

Rather than add additional user attributes to the Membership system, Microsoft instead created the Profile system to handle additional user properties. The Profile system allows the additional, user-specific properties to be defined in the Web. Config file and is responsible for persisting these values to some data store.

Reference: Examining ASP. NET's Membership, Roles, and Profile - Part 6.

– ashuthinks Jan 6 at 17:44 @ashuthinks If you read that article it shows you the easier way to extend functionaries of ASP. NET Membership. – Jani Jan 6 at 17:50 But If you want to go with this code you should update the user row after created by Membership Provider outside of this method.

– Jani Jan 6 at 17:52.

This is how I have accomplished somthing like this. I added event onCreatedUser to CreateUserWizard and when you press CreateUser button it loads method protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e) { MembershipUser mu = Membership. GetUser(CreateUserWizard1.

UserName); int idOfInsertedUser = (int)mu. ProviderUserKey; TextBox tb1 = (TextBox)CreateUserWizard1.CreateUserStep. ContentTemplateContainer.

FindControl("FirstName"; string firstName= tb1. Text; TextBox tb2 = (TextBox)CreateUserWizard1.CreateUserStep. ContentTemplateContainer.

FindControl("LastName"; string lastName= tb2. Text; // now you have values of two more fields, and it is time to call your Database methods for inserting them in tables of choice... }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions