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

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

问题描述

我想用我自己的SQL Server数据库来存储用户权限。

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

我初始化UserStore与我的背景是这样(我试过用默认构造也)

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.

然后,我改变web配置我的连接

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结果=等待UserManager.CreateAsync(用户);

它会调用

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.

我试过了更改连接名称 DefaultConnection ,但没有成功。

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

我想上<一的建议href=\"http://stackoverflow.com/questions/21343846/change-the-database-in-which-asp-net-identity-stores-user-data\">question我改变了的DbContext IdentityDbContext&LT; IdentityUser&GT;

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.

我不知道,如果在网络配置中的EntityFramework设置可能是问题

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?

感谢您

推荐答案

使用下面的连接字符串解决了这个问题对我来说:

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天全站免登陆