亲爱的参与者,我请求您帮助解决这个问题:在ASP.Net 6上有一个连接了Microsoft 身份授权的站点,托管在IIS 10 (WinServer 2022)下。在开发中,用户授权(在设置“记住我”复选框时)从此过着幸福的生活。但是,在服务器上,大约10-20 分钟后,授权丢失,您必须重新登录。
这是 IdentityOptions 设置
/* Настройки UserIdentityContext */
services.AddDbContext<UserIdentityContext>(
options => options.UseSqlServer(Configuration["ConnectionStrings:users_db"]));
IdentityBuilder ibuilder = services.AddIdentity<RnrmmUser, IdentityRole<Guid>>();
ibuilder.AddEntityFrameworkStores<UserIdentityContext>();
ibuilder.AddErrorDescriber<IdentityRussianErrorDescriber>();
ibuilder.AddDefaultTokenProviders();
services.Configure<SecurityStampValidatorOptions>(static options =>
options.ValidationInterval = TimeSpan.FromHours(1));
services.AddAuthentication().
Services.ConfigureApplicationCookie(static options => {
options.SlidingExpiration = true;
options.ExpireTimeSpan = TimeSpan.FromDays(7);
});
services.Configure<IdentityOptions>(static options => {
options.Password.RequiredLength = 8;
options.Password.RequireNonAlphanumeric = true;
options.Password.RequireLowercase = true;
options.Password.RequireUppercase = true;
options.Password.RequireDigit = true;
options.User.RequireUniqueEmail = true;
options.SignIn.RequireConfirmedAccount = true;
options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(15);
options.Lockout.MaxFailedAccessAttempts = 10;
options.Lockout.AllowedForNewUsers = true;
});
这是我的 Web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<rewrite>
<rules>
<rule name="Перенаправление на https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
</rule>
</rules>
</rewrite>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\rnrmm_ru.exe" stdoutLogEnabled="true" stdoutLogFile="w:\logs\rnrmm\errorlog" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
我是如何尝试解决问题的: 我尝试增加 cookie 的寿命,如下所示:
//Для поддержки сессий
services.AddDistributedMemoryCache();
services.AddSession(static options =>
{
options.Cookie.Name = ".rnrmm.session.data";
options.Cookie.IsEssential = true;
options.Cookie.HttpOnly = false;
options.Cookie.SecurePolicy = CookieSecurePolicy.Always;
//Время ожидания
options.IdleTimeout = TimeSpan.FromDays(1);
});
一般来说,问题出在 IIS 中。您可以在此处阅读有关 IIS 中的错误的更多信息。
解决方案 在应用程序池中,选择站点池,打开高级选项,并将“加载用户配置文件”设置为 true。