【发布时间】:2022-01-13 15:41:00
【问题描述】:
创建的任何新用户都正确显示在 AspNetUsers 表中。
在我的 Startup 类的 MVC Web 应用程序中,我有以下 ConfigureAuth 方法(几乎是开箱即用的代码)
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);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
// Enable the application to use a cookie to store information for the signed in user
// and to use a cookie to temporarily store information about a user logging in with a third party login provider
// Configure the sign in cookie
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
// Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
// Enables the application to remember the second login verification factor such as phone or email.
// Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
// This is similar to the RememberMe option when you log in.
app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
// Uncomment the following lines to enable logging in with third party login providers
//app.UseMicrosoftAccountAuthentication(
// clientId: "",
// clientSecret: "");
//app.UseTwitterAuthentication(
// consumerKey: "",
// consumerSecret: "";
//app.UseFacebookAuthentication(
// appId: "",
// appSecret: "");
//app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
//{
// ClientId = "",
// ClientSecret = ""
//});
}
我的web.config连接字符串如下
<add name="DefaultConnection" connectionString="Data Source=localhost\SQLEXPRESS;Initial Catalog=DbName;Integrated Security=True;MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" />
但是,大约一周前,我收到一条错误消息,抱怨我的 App_Data 文件夹中有一个 ASPNETDB.MDF 文件。我检查了这个 ASPNETDB 数据库中的内容,它包含以下表格。
当我通过我的应用程序创建用户时,它仍然将它们添加到原始数据库中,而不是 ASPNETDB.MDF 数据库中,这正是我想要的。
我将最新的代码更改部署到我的生产站点,但我收到有关 ASPNETDB.MDF 文件的错误消息。
尝试为文件附加自动命名的数据库 C:...\App_Data\aspnetdb.mdf 失败。同名数据库 存在,或指定的文件无法打开,或位于 UNC 分享。
谁能指出我为什么会收到这个错误的正确方向,更重要的是我做了什么让我的应用程序开始创建这个 ASPNETDB.MDF 文件?
【问题讨论】:
标签: c# asp.net-mvc asp.net-identity