我已将 ASP.NET 核心 2.1 应用程序部署在 Docker 容器中的 AWS 负载均衡器后面。当我尝试从登录页面登录应用程序时。我得到 InvalidOperationException,理由如下:
未指定身份验证方案,并且未找到 DefaultChallengeScheme。
但是当我再次点击相同的URL时,它实际上移动到正确的页面并工作了一段时间,然后再次抛出HTTP状态为500的相同异常,并且在第二次尝试打开同一页面后,它成功了。有趣的是,Chrome并不像IE那样健壮:如果IE在异常后无法恢复,Chrome总是在随后提交页面时返回404,这会产生上述异常。
因此,如果有人能够为我提供如何补救这种情况的想法,我将不胜感激 显然问题与身份验证有关,但我无法弄清楚应该做什么。
以下是Startup.cs中的ConfigalServices()的相关练习:
string appname = "MyApp";
var redis = ConnectionMultiplexer.Connect(Configuration.GetConnectionString("RedisConnection"));
services.AddDataProtection()
.SetApplicationName(appname)
.PersistKeysToRedis(redis, "DataProtectionKeys")
.ProtectKeysWithCertificate(LoadCert(Configuration));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddAuthentication( CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme,
options =>
{
options.LoginPath = new PathString("/Area/Ctrl/Login");
options.LogoutPath = new PathString("/Area/Ctrl/Logout");
options.Cookie.IsEssential = true;
});
services.AddDistributedRedisCache(o =>
{
o.Configuration = Configuration.GetConnectionString("RedisConnection");
});
services.AddSession(options =>
{
options.Cookie.Name = appname;
options.IdleTimeout = TimeSpan.FromSeconds(600);
});
以下是Startup.cs中的Configor()中的相关代码:
app.UseForwardedHeaders();
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAuthentication();
app.UseSession();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "areas",
template: "{area:exists}/{controller=Ctrl}/{action=Login}/{id?}"
);
});
小唯快跑啊
相关分类