c# - 502 Bad Gateway / passwordsigninasync 调用失败
问题描述
Microsoft.AspNetCore.Identity.SignInResult loSignInResult = await base._oLoginManager.PasswordSignInAsync(loUser.UserName, lsPassword, true, false);
这是导致 502 Bad Gateway 消息的行。
请看下面的启动程序(发生此错误时_bStaging为false),我尝试重新排序代码但没有成功。前几天没有重大代码更改就开始发生此错误。没有对服务器进行任何更改,只有我可以访问。:
public void ConfigureServices(IServiceCollection loServices)
{
try
{
if (!this._bIsStaging)
{
loServices.Configure<MvcOptions>(options =>
{
options.Filters.Add(new RequireHttpsAttribute());
});
}
loServices.AddSession();
Heron.Data.Classes.ConnectionStrings._sHeronConnectionString = this._oConfiguration.GetConnectionString(this.GetConnectionStringName("Heron"));
Heron.Data.Classes.ConnectionStrings._sIdentityConnectionString = this._oConfiguration.GetConnectionString(this.GetConnectionStringName("Identity"));
loServices.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
loServices.AddDbContext<Heron.Data.DB.HeronContext>(O => O.UseSqlServer(Heron.Data.Classes.ConnectionStrings._sHeronConnectionString));
loServices.AddScoped<DbContext>(sp => sp.GetService<Heron.Data.DB.HeronContext>());
loServices.AddDbContext<Heron.Data.DB.Extensions.IdentityExtend.DbContext>(O => O.UseSqlServer(Heron.Data.Classes.ConnectionStrings._sIdentityConnectionString));
loServices.AddScoped<DbContext>(sp => sp.GetService<Heron.Data.DB.Extensions.IdentityExtend.DbContext>());
loServices.AddIdentity<Heron.Data.DB.Extensions.IdentityExtend.User, Heron.Data.DB.Extensions.IdentityExtend.Role>(opts =>
{
opts.Lockout.DefaultLockoutTimeSpan = new TimeSpan(0, 0, Heron.Library.Classes.Constants._nDefaultLockoutTime, 0);
opts.Lockout.MaxFailedAccessAttempts = Heron.Library.Classes.Constants._nMaxFailedAccessAttempts;
opts.Lockout.AllowedForNewUsers = true;
opts.Password.RequireDigit = true;
opts.Password.RequireLowercase = true;
opts.Password.RequireUppercase = true;
opts.Password.RequireNonAlphanumeric = true;
opts.Password.RequiredLength = Heron.Library.Classes.Constants._nMinRequiredDigitsPassword;
}).AddEntityFrameworkStores<Heron.Data.DB.Extensions.IdentityExtend.DbContext>().AddDefaultTokenProviders().AddUserManager<UserManager<Heron.Data.DB.Extensions.IdentityExtend.User>>();
loServices.AddScoped<SignInManager<Heron.Data.DB.Extensions.IdentityExtend.User>>();
loServices.AddScoped<UserManager<Heron.Data.DB.Extensions.IdentityExtend.User>>();
loServices.AddScoped<RoleManager<Heron.Data.DB.Extensions.IdentityExtend.Role>>();
loServices.ConfigureApplicationCookie(options =>
{
options.LoginPath = new PathString("/Account/Index");
options.Cookie.Name = "HeronAuthCookie";
options.Cookie.HttpOnly = true;
});
loServices.AddAuthentication(o =>
{
o.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
o.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
o.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
o.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie(options =>
{
options.LoginPath = "/Account/Index";
});
loServices.AddDistributedMemoryCache();
loServices.AddMvcCore(options =>
{
options.RespectBrowserAcceptHeader = true;
})
.AddJsonFormatters();
loServices
.AddMvc(options =>
{
options.Filters.Add(new AuthorizeFilter(new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build()));
})
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
.AddSessionStateTempDataProvider()
.AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());
loServices.AddKendo();
loServices.Configure<RecaptchaSettings>(this._oConfiguration.GetSection("RecaptchaSettings"));
loServices.AddTransient<IRecaptchaService, RecaptchaService>();
loServices.Configure<IISOptions>(this._oConfiguration);
loServices.Configure<RequestLocalizationOptions>(options =>
{
options.RequestCultureProviders.Clear();
options.DefaultRequestCulture = new Microsoft.AspNetCore.Localization.RequestCulture("en-GB");
options.SupportedCultures = new List<CultureInfo> { new CultureInfo("en-GB") };
});
}
catch (Exception loException)
{
Heron.Library.Classes.Utility.MakeExceptionMessage(loException, "\r\n", "Startup.ConfigureServices");
}
}
public void Configure(IApplicationBuilder loApp, IHostingEnvironment loEnv)
{
try
{
if (!this._bIsStaging)
{
loApp.UseHttpsRedirection();
}
using (var serviceScope = loApp.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope())
{
var loContext = serviceScope.ServiceProvider.GetService<Heron.Data.DB.HeronContext>();
loContext.Database.EnsureCreated();
loContext.Database.Migrate();
var loContext2 = serviceScope.ServiceProvider.GetService<Heron.Data.DB.Extensions.IdentityExtend.DbContext>();
loContext2.Database.EnsureCreated();
}
if (loEnv.IsDevelopment())
{
loApp.UseDeveloperExceptionPage();
}
else
{
loApp.UseExceptionHandler("/Shared/Error");
loApp.UseHsts();
}
loApp.UseStatusCodePages(async context =>
{
context.HttpContext.Response.ContentType = "text/plain";
await context.HttpContext.Response.WriteAsync("Status code page, status code: " + context.HttpContext.Response.StatusCode);
});
loApp.UseStaticFiles();
loApp.UseSession();
loApp.UseCookiePolicy();
loApp.UseAuthentication();
loApp.UseMvc(routes =>
{
routes.MapRoute(name: "dashboard", template: "{controller=Dashboard}/{action=Index}/{lsData?}");
routes.MapRoute(name: "default", template: "{controller=Account}/{action=Index}/{lsMessage?}");
});
var supportedCultures = new[] { new CultureInfo("en-GB") };
loApp.UseRequestLocalization(new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture("en-GB"),
SupportedCultures = supportedCultures,
SupportedUICultures = supportedCultures
});
}
catch (Exception loException)
{
Heron.Library.Classes.Utility.MakeExceptionMessage(loException, "\r\n", "Startup.Configure");
}
}
解决方案
已经找到了解决方案...
https://forums.asp.net/p/2156143/6266248.aspx?p=True&t=636961808361687440
见上面的线程。
本质上,它是一个用户声明值,其中包含超过响应标头大小的图像。
这对于核心来说可能是一个问题,因为在 userclaim 中为身份用户存储图像(头像)的好地方。
暂时的。
大卫
推荐阅读
- java - 如果我将类的实例变量与对象进行比较,它将比较什么?
- android - 如何仅从 android 中的网页 url 获取图像
- sql - 使用行号的 PostgreSQL 百分比变化
- django - Django React Image 不会显示
- python - Django Allauth facebook 登录错误“应用程序未使用安全连接传输信息”
- python - 如何为我的班级实例设置一组特定的打印指令?
- python - Python Pandas - 根据值的某些条件选择多级索引
- javascript - 如何在 chart.js 中捕获过滤器选择事件
- python - 在python中将3个字典合并为一个
- swift - Firebase 中的 updateData 函数无法识别文档字段