问题
I am creating a Log in scheme using SimpleMembershipProvider in MVC4. I wanted a little more control than what i get with the out of the box AccountControl. So I have modified the connections to use my database and table, however I would like fields like first name, last name and email to be required.
WebSecurity.CreateUserAndRole(username, password);
fails because of the required field types. I have found that I can use PropertyValues to fix this issue, however I cannot figure out how to make PropertyValues equal more than one value.
WebSecurity.CreateUserAndAccount(user.Username, user.password, propertyValues: new {firstName = user.firstName});
How do I go about using multiple PropertyValues?
回答1:
I'm not sure, but can you maybe try adding another entry to the new {} object you're creating. Something like:
WebSecurity.CreateUserAndAccount(user.Username, user.password,
propertyValues: new {firstName = user.firstName,
lastName = user.lastName});
回答2:
You must add column (firstName & lastName) to table dbo.UserProfile in aspnet DB (in folder app_data) for using:
WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new {firstName = user.firstName, lastName = user.lastName});
来源:https://stackoverflow.com/questions/14416728/simplemembershipprovider-using-multiple-propertyvalues-with-custom-database-tab