将connectionString传递给ApplicationDbContext

时间:2015-10-08 16:49:54

标签: c# asp.net asp.net-identity

我正在尝试将connectionString传递给ApplicationDbContext,但是它是根据传递给登录页面的一些细节确定的,但是我只能知道如何从Startup.Auth.cs页面传递它。

我的Web应用程序基本上在数据库中进行查找,以确定用户将连接到哪个DB。我需要传递connectionString,无论是在Login页面中传递它还是将它存储在某处并在Startup.Auth.cs中检索它,这是我到目前为止所拥有的:

   public void ConfigureAuth(IAppBuilder app)
        {
            // Configure the db context, user manager and signin manager to use a single instance per request

            app.CreatePerOwinContext(() => ApplicationDbContext.Create("ConnectionString"));

由于

1 个答案:

答案 0 :(得分:1)

在您需要之前不要创建ApplicationDbContext,此时您应该知道要使用的连接字符串。