简体   繁体   English

502 Bad Gateway /在passwordigninasync调用失败

[英]502 Bad Gateway / failing on passwordsigninasync call

Microsoft.AspNetCore.Identity.SignInResult loSignInResult = await base._oLoginManager.PasswordSignInAsync(loUser.UserName, lsPassword, true, false);

This is the line that causes the 502 Bad Gateway message. 这是导致502 Bad Gateway消息的行。

Please see the startup program below (_bStaging is false when this error occurs), I have tried to reorder the code without success. 请参阅下面的启动程序(发生此错误时_bStaging为false),我试图重新排序代码但没有成功。 This error started occurring the other day without a significant code change. 此错误在前一天开始发生,没有重大的代码更改。 No changes were made to the server, and only I have access.: 没有对服务器进行任何更改,只有我有权访问:

    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");
        }
    }

上面一行执行后出现Bad Gateway消息...

A solution to this has been found... 已找到解决方案......

https://forums.asp.net/p/2156143/6266248.aspx?p=True&t=636961808361687440 https://forums.asp.net/p/2156143/6266248.aspx?p=True&t=636961808361687440

See above thread. 见上面的主题。

In essence it was a user claim value containing an image which exceeded the response header size. 实质上,它是一个用户声明值,其中包含超出响应标头大小的图像。

This might be a problem for core as a nice place to store an image (avatar) for an identity user is within userclaim. 这可能是核心的问题,因为存储身份用户的图像(化身)的好地方在userclaim内。

All for now. 一切都是现在。

David 大卫

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM