ASP.Net Identity customizing UserProfile

别等时光非礼了梦想. 提交于 2019-12-22 01:15:48

问题


I'm writing an MVC5 app with EF. I added ASP.NET Identity to the project which created ASPNETUser Tables in my DB the first time I registered a user. However now, when I try to customize UserProfile (as listed in this post: http://www.asp.net/mvc/tutorials/mvc-5/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on)

I get the following:

The model backing the 'ApplicationDbContext' context has changed since the database was created. Consider using Code First Migrations to update the database

Is it because I already have .edmx file specified (MVC5Entities) => (see 2 connection strings in web.config)?

This is my web.config:

  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=DILS-S1301;Initial Catalog=MVC5;Integrated Security=True" providerName="System.Data.SqlClient" />
  <add name="MVC5Entities" connectionString="metadata=res://*/Models.Mvc5Model.csdl|res://*/Models.Mvc5Model.ssdl|res://*/Models.Mvc5Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DILS-S1301;initial catalog=MVC5;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

How would I do it?


回答1:


First, I think it does not matter if you have one or more connectionStrings. But you should make sure in the "IdentityModels.cs" file, ApplicationDbContext will use your main connectionString and not the default conncetionString. Like below:

public ApplicationDbContext() : base("MVC5Entities")
{
}

Second, if you added some profile data for the user, you need to update your database using migrations.

1) go to Package Manager Console

2) -> Enable-Migrations

3) -> Add-Migration init

4) -> Update-Database

Hope it helps.



来源:https://stackoverflow.com/questions/19814432/asp-net-identity-customizing-userprofile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!