IdentityServer4 SQLite错误1:&x27;没有这样的表:AspNetUserLogins';
我正在尝试使用IdentityServer4,并坚持使用它的内存实现。我基本上使用的是来自Quickstart示例的 代码在localhost中运行良好,但在IIS中将其发布到服务器后,我现在收到一个SQLite错误1:“没有这样的表:AspNetUserLogins”。 数据库文件位于应用程序的内容根文件夹中,具有正确的文件权限。检查后,它确实有表AspNetUserLogins 下面是Startup.cs中的代码片段:IdentityServer4 SQLite错误1:&x27;没有这样的表:AspNetUserLogins';,sqlite,asp.net-identity,asp.net-core-2.0,identityserver4,Sqlite,Asp.net Identity,Asp.net Core 2.0,Identityserver4,我正在尝试使用IdentityServer4,并坚持使用它的内存实现。我基本上使用的是来自Quickstart示例的 代码在localhost中运行良好,但在IIS中将其发布到服务器后,我现在收到一个SQLite错误1:“没有这样的表:AspNetUserLogins”。 数据库文件位于应用程序的内容根文件夹中,具有正确的文件权限。检查后,它确实有表AspNetUserLogins 下面是Startup.cs中的代码片段: public Startup(IConfiguration confi
public Startup(IConfiguration configuration, IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
Environment = env;
}
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite($"Data Source={Environment.ContentRootPath}/AspIdUsers.db"));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc();
services.Configure<IISOptions>(iis =>
{
iis.AuthenticationDisplayName = "Windows";
iis.AutomaticAuthentication = false;
});
var builder = services.AddIdentityServer(options =>
{
options.Events.RaiseErrorEvents = true;
options.Events.RaiseInformationEvents = true;
options.Events.RaiseFailureEvents = true;
options.Events.RaiseSuccessEvents = true;
})
.AddInMemoryIdentityResources(Config.GetIdentityResources())
.AddInMemoryApiResources(Config.GetApiResources())
.AddInMemoryClients(Config.GetClients())
.AddAspNetIdentity<ApplicationUser>();
有人能告诉我这件事吗。我在这里遗漏了什么?我会冒险猜测,
$”数据源={Environment.ContentRootPath}/AspIdUsers.db“
处的数据库文件找不到-是否创建了一个空文件?如果找不到它,它将抛出另一个错误。问题是我试图做的只是使用.NETCoreIdentity(据说它使用EF和数据库迁移)的半成品,并且仍然坚持内存中的实现。我想唯一的办法是要么完全放弃.net核心身份,要么继续做完整的EF。请参阅。
/// <summary>
/// Post processing of external authentication
/// </summary>
[HttpGet]
public async Task<IActionResult> ExternalLoginCallback()
{
// read external identity from the temporary cookie
var result = await HttpContext.AuthenticateAsync(IdentityConstants.ExternalScheme);
if (result?.Succeeded != true)
{
throw new Exception("External authentication error");
}
// lookup our user and external provider info
var (user, provider, providerUserId, claims) = await FindUserFromExternalProviderAsync(result);
private async Task<(ApplicationUser user, string provider, string providerUserId, IEnumerable<Claim> claims)>
FindUserFromExternalProviderAsync(AuthenticateResult result)
{
var externalUser = result.Principal;
// try to determine the unique id of the external user (issued by the provider)
// the most common claim type for that are the sub claim and the NameIdentifier
// depending on the external provider, some other claim type might be used
var userIdClaim = externalUser.FindFirst(JwtClaimTypes.Subject) ??
externalUser.FindFirst(ClaimTypes.NameIdentifier) ??
throw new Exception("Unknown userid");
// remove the user id claim so we don't include it as an extra claim if/when we provision the user
var claims = externalUser.Claims.ToList();
claims.Remove(userIdClaim);
var provider = result.Properties.Items["scheme"];
var providerUserId = userIdClaim.Value;
// find external user
var user = new ApplicationUser();
try
{
user = await _userManager.FindByLoginAsync(provider, providerUserId);
}
catch (Exception ex)
{
throw(ex);
}
return (user, provider, providerUserId, claims);
}
user = await _userManager.FindByLoginAsync(provider, providerUserId);