(解决方案在Chris发表 comments 后分为单独的答案)
我找到了一个解决方案来保持登录状态,它在网站停止/启动和网站源文件夹更新后仍然有效:
public void ConfigureServices(IServiceCollection services)
{
services.AddDataProtection()
// This helps surviving a restart: a same app will find back its keys. Just ensure to create the folder.
.PersistKeysToFileSystem(new DirectoryInfo("\\MyFolder\\keys\\"))
// This helps surviving a site update: each app has its own store, building the site creates a new app
.SetApplicationName("MyWebsite")
.SetDefaultKeyLifetime(TimeSpan.FromDays(90));
}
有了这些附加行和机器密钥集,在站点停止/启动和IIS服务器重新启动之后,如果重新构建站点,登录数据将保持不变.
更多信息:https://docs.microsoft.com/en-us/aspnet/core/security/data-protection/configuration/overview
Just Serega提出的更多建议:
https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/advanced?view=aspnetcore-6.0#data-protection个