UserStore与我自己的数据库 [英] UserStore with my own database

查看:168
本文介绍了UserStore与我自己的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我用自己的SQL Server数据库存储用户权限。构造函数)

  UserManagerFactory =()=> new UserManager< IdentityUser>(new UserStore< IdentityUser>(new DbEpicerieEntities())); 

然后我创建一个空数据库,并为实体生成数据模型。



然后我更改了我的连接的web配置

 < connectionStrings> 
< add name =DefaultConnectionconnectionString =metadata = res://*/Models.EpicerieModel.csdl | res://*/Models.EpicerieModel.ssdl | res://*/Models.EpicerieModel .msl; provider = System.Data.SqlClient; provider connection string =& quot; data source = localhost; initial catalog = DbEpicerie; integrated security = True; MultipleActiveResultSets = True; App = EntityFramework& quot; providerName =System.Data.EntityClient/>
< / connectionStrings>

但它不工作。如果我尝试注册一个用户,在



IdentityResult result = await UserManager.CreateAsync(user);



它将调用

  protected override void Dispose(bool disposal)
{
if(disposal)
{
UserManager.Dispose();
}

base.Dispose(处置);
}

我尝试使用已经制作的表的数据库,但是我有相同的结果。



我尝试更改 DefaultConnection 但没有成功的连接名称。



我尝试了关于问题,我将 DbContext 更改为 IdentityDbContext< IdentityUser>

  public partial class DbEpicerieEntities:IdentityDbContext< IdentityUser> 
{
public DbEpicerieEntities()
:base(DefaultConnection)
{
}

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}

}

但我也有同样的问题。



我不知道Web配置中的EntityFramework设置是否可能是问题

 <&的EntityFramework GT; 
< defaultConnectionFactory type =System.Data.Entity.Infrastructure.SqlConnectionFactory,EntityFramework/>
< providers>
< provider invariantName =System.Data.SqlClienttype =System.Data.Entity.SqlServer.SqlProviderServices,EntityFramework.SqlServer/>
< / providers>
< / entityFramework>

任何想法为什么不起作用?



谢谢

解决方案

使用以下连接字符串解决了我的问题:

 < add name =DefaultConnectionconnectionString =Data Source = localhost; Initial Catalog = Epicerie; Integrated Security = True; providerName =System.Data.SqlClient/> 


I'm trying to use my own SQL Server database to store the user permissions.

I initialize the UserStore with my context like this (I tried with the default constructor also)

UserManagerFactory = () => new UserManager<IdentityUser>(new UserStore<IdentityUser>(new DbEpicerieEntities()));

Then I created an empty database and generated the data model for entity.

Then I changed the web config for my connection

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

But it doesn't work. If I try to register a user, after

IdentityResult result = await UserManager.CreateAsync(user);

it will call

protected override void Dispose(bool disposing)
{
    if (disposing)
    {
       UserManager.Dispose();
    }

    base.Dispose(disposing);
}

I tried to use a database with tables already made, but I have the same result.

I tried to change the connection name for DefaultConnection but no success.

I tried the recommendations on that question and I changed DbContext to IdentityDbContext<IdentityUser>

public partial class DbEpicerieEntities : IdentityDbContext<IdentityUser>
    {
        public DbEpicerieEntities()
            : base("DefaultConnection")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }

    }

but I have the same problem.

I don't know if the EntityFramework setting in the web config could be the problem

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>

Any ideas why it doesn't work?

Thank you

解决方案

Using the following connection string solved the problem for me :

<add name="DefaultConnection" connectionString="Data Source=localhost;Initial Catalog=Epicerie;Integrated Security=True;" providerName="System.Data.SqlClient" />

这篇关于UserStore与我自己的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆