将 connectionString 传递给 ApplicationDbContext

Passing connectionString to ApplicationDbContext

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

我的 Web 应用程序主要是在数据库中查找以确定用户将连接到哪个数据库。我需要通过将连接字符串传递到登录页面或将其存储在某处并在 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"));

谢谢

除非需要,否则不要创建 ApplicationDbContext,此时您应该知道要使用的连接字符串。