部署后,ASP.Net Core Identity登录状态丢失

编程入门 行业动态 更新时间:2024-10-11 07:30:29
本文介绍了部署后,ASP.Net Core Identity登录状态丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用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登录状态丢失

本文发布于:2023-11-17 09:07:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609565.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:状态   Net   ASP   Identity   Core

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!