因此,在发布到IIS8(WINDOWS SERVER)时,我在生产环境中遇到了奇怪的问题。 当我将新代码发布到生产或登台(远程服务器)用户发布后获得502错误:
502 - Web server received an invalid response while acting as a gateway or proxy server.
There is a problem with the page you are looking for, and it cannot be displayed. When the Web server (while acting as a gateway or proxy) contacted the upstream content server, it received an invalid response from the content server.
仅在帐户/登录和帐户/注册视图中发生。所有其他视图都正常工作。 唯一的解决方案是清除cookie " .AspNetCore.Antiforgery.pLfhSuGokUU" 。之后它可以正常工作。
这是我的启动配置: //运行时调用此方法。使用此方法将服务添加到容器。 public void ConfigureServices(IServiceCollection services) { services.AddMemoryCache(); services.AddLogging();
// Add framework services.
services.AddDbContext<CaseweekDbContext>(opts =>
{
//Switch diffrent databases to diffrent enviroments
if (CurrentEnvironment.IsProduction()){
opts.UseSqlServer(Configuration.GetConnectionString("ProductionConnection"));
}else if (CurrentEnvironment.IsStaging())
{
opts.UseSqlServer(Configuration.GetConnectionString("StagingConnection"));
} else if (CurrentEnvironment.IsDevelopment())
{
opts.UseSqlServer(Configuration.GetConnectionString("DevelopmentConnection"));
}
});
services.AddScoped<DbContext, CaseweekDbContext>();
services.AddScoped<IUserStore<ApplicationUser>, CaseweekUserStore>();
services.AddScoped<IRoleStore<CaseweekIdentityRole>, CaseweekRoleStore>();
// Add Identity services to the services container.
services.AddIdentity<ApplicationUser, CaseweekIdentityRole>(identityOptions =>
{
identityOptions.Cookies.ApplicationCookie.AuthenticationScheme = AuthenticationTypes.CookieAuthentication;
identityOptions.Password = new PasswordOptions()
{
RequireDigit = true,
RequireLowercase = true,
RequireUppercase = false,
RequiredLength = 6,
RequireNonAlphanumeric = false
};
})
.AddDefaultTokenProviders();
services.AddAuthorization(PolicyConfigurator.ConfigurePolicies);
services.AddOptions();
ApplicationConfigurator.ConfigureApp(services, Configuration);
services
.AddMvc(opts =>
{
FilterConfig.ConfigureFilters(opts.Filters);
});
services.AddSession();
services.AddDbLogger<CaseweekDbContext, EntityFrameworkLog>((p) => new DbLogContextFactory());
//configuring security policies
services.AddSingleton<IAuthorizationHandler, ClaimRequirementHandler>();
services.AddScoped<IValidatorFactory, ServiceProviderValidatorFactory>();
DI.ConfigureServices(services);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IServiceProvider serviceProvider)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
loggerFactory.AddDbLoggerProvider<CaseweekDbContext, EntityFrameworkLog>(serviceProvider);
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseSession();
//Cookie authentication
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AuthenticationScheme = AuthenticationTypes.CookieAuthentication,
LoginPath = new PathString("/Account/Login"),
AccessDeniedPath = new PathString("/Error/Forbidden"),
AutomaticAuthenticate = true,
AutomaticChallenge = true
});
app.UseMvc(RouteConfig.ConfigureRoutes);
app.UseIdentity();
Seed(app);
}