如果您在使用ASP.NET Core 2.1的过程中在本地工作时遇到了问题,但在IIS中出现问题,可以尝试通过以下代码示例解决:
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie(options =>
{
options.ExpireTimeSpan = TimeSpan.FromMinutes(30); // 设置Cookie过期时间
options.SlidingExpiration = true; // 启用滑动过期
});
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// 省略其他配置代码
app.UseAuthentication();
app.UseMvc();
}
public void ConfigureServices(IServiceCollection services)
{
services.Configure(options =>
{
options.ValidationInterval = TimeSpan.FromSeconds(5); // 本地工作时设置更短的间隔时间
});
// 省略其他配置代码
}
请注意,这只是解决问题的一种可能方法。根据您的具体情况,可能需要进一步调整配置。