ASP.Net身份定制用户配置 [英] ASP.Net Identity customizing UserProfile
问题描述
我在写与EF的MVC5应用程序。我加了ASP.NET身份产生它ASPNETUser表在我的数据库,我第一次注册的用户项目。但是现在,当我尝试自定义用户配置(在这篇文章中列出:<一href=\"http://www.asp.net/mvc/tutorials/mvc-5/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on\" rel=\"nofollow\">http://www.asp.net/mvc/tutorials/mvc-5/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on)
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)
我收到以下内容:
The model backing the 'ApplicationDbContext' context has changed since the database was created. Consider using Code First Migrations to update the database
难道是因为我已经有.edmx文件指定(MVC5Entities)=>(见在web.config中2连接字符串)?
Is it because I already have .edmx file specified (MVC5Entities) => (see 2 connection strings in web.config)?
这是我的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="data source=DILS-S1301;initial catalog=MVC5;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
我会怎么做呢?
推荐答案
首先,我认为,如果你有一个或多个是connectionStrings没关系。
但是,你应该确保在IdentityModels.cs的文件,ApplicationDbContext会使用你的主要的connectionString,而不是默认的conncetionString。
象下面这样:
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)去打包Manager控制台
1) go to Package Manager Console
2) - >启用的迁移
2) -> Enable-Migrations
3) - >添加迁移的init
3) -> Add-Migration init
4) - >更新 - 数据库
4) -> Update-Database
希望它帮助。
这篇关于ASP.Net身份定制用户配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!