Move ASP.NET Identity store to EF Sql database

久未见 提交于 2019-12-22 08:58:08

问题


By default ASP.NET Identity user data is stored in an mdf file.

I want to store the data in a Sql database so that I changed the defaultconnection string in my web.config to my EF based connection:

 <add name="DefaultConnection" connectionString="metadata=res://*/Models.StartifyModel.csdl|res://*/Models.StartifyModel.ssdl|res://*/Models.StartifyModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=MYPC\SQLEXPRESS;initial catalog=mydb;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

Now I am getting the error The entity type ApplicationUser is not part of the model for the current context. as soon as I want to register a user.

I use the default MVC5 project template of VS2013.


回答1:


Please try specify the connection string in the format:

<add name="DefaultConnection" connectionString="Data Source=127.0.0.1, 1433;Initial Catalog=YourDB;User Id=XXXX;Password=XXXXX;Asynchronous Processing=True;Encrypt=False;TrustServerCertificate=True;Persist Security Info=True" providerName="System.Data.SqlClient" />

And then make sure in Models/IdentityModels.cs you have

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext()
            : base("DefaultConnection")
        {
        }


来源:https://stackoverflow.com/questions/19612734/move-asp-net-identity-store-to-ef-sql-database

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