我正在使用ASP.Net Core和MS Identity,我试图了解为什么每次部署后登录用户都注销. 我在IIS 8.5上运行
I am using ASP.Net Core and MS Identity, I try to understand why after each deployment the login users are logged out. I am running on a IIS 8.5
我一直在尝试此线程中的方法(设置静态机器密钥) 部署后的ASP.NET Identity 2重新登录 通过在IIS UI中在服务器级别生成静态密钥并将以下内容添加到网站的web.config中:
I have been trying the method in this thread (setting static machine key) ASP.NET Identity 2 relogin after deploy by generating static keys at the server level in IIS UI and adding the following to web.config of the website:
<system.web> <machineKey validationKey="XXX" decryptionKey="XXX" validation="SHA1" decryption="AES"/> </system.web>但是问题仍然存在:
- 用户登录
- 停止站点
- 起始站点
- 用户需要重新登录
但是我也要这样做:
- 用户登录
- 重新启动网站
- 用户仍处于登录状态
什么会导致用户注销?关于如何避免这种想法?
What can cause the user to be logged off? Any idea on how to avoid that?
推荐答案(解决方案在克里斯评论后拆分为单独的答案)
(solution split into a separate answer following Chris comment)
我找到了一种保持登录状态的解决方案,它可以在网站停止/启动以及网站源文件夹更新的情况下幸免于难:
I found a solution to keep the login status, it survives website stop/start, and an update of the website source folder:
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服务器重新启动以及重新构建站点后保留.
With these additional lines and the machine key set, the login data stays after site stop/start and IIS server restart, and if the site is rebuilt.
那里有更多信息: docs.microsoft/en-us/aspnet/core/security/data-protection/configuration/overview
justserega提出的更多建议: docs.microsoft/en-us/aspnet/core/host-and-deploy/iis/?tabs=aspnetcore2x#data-protection
More proposed by justserega: docs.microsoft/en-us/aspnet/core/host-and-deploy/iis/?tabs=aspnetcore2x#data-protection
更多推荐
部署后,ASP.Net Core Identity登录状态丢失
发布评论