部署后ASP.NET Identity 2重新登录 [英] ASP.NET Identity 2 relogin after deploy

查看:110
本文介绍了部署后ASP.NET Identity 2重新登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将asp.net mvc 5与Identity2(标准登录/密码身份验证)一起使用,并带有记住我"复选框.

I'm using asp.net mvc 5 together with Identity2, standard login/password authentication, with "remember me" checkbox.

想象一下场景:

  • 用户登录(标准身份验证cookie)
  • 应用已重新部署
  • 用户需要重新登录.

问题:

  1. 是否可以在部署后不重新登录?
  2. 有时,在刷新页面后,部署后,需要授权访问-可以正确显示,但是如果第二次刷新-它会重定向到登录页面.

所有这些都发生在部署到IIS Express上的IIS7上时,一切正常.

All these happens when deployed to IIS7, locally on IIS Express everything is ok.

推荐答案

您必须重新登录的原因是因为计算机密钥已更改.机器密钥加密用于加密和解密身份验证cookie.由于无法解密现有的Cookie,因此该用户被视为未经授权,需要再次登录.

The reason that you have to relogin is because the machine key changes. The machine key encryption is used to encrypt and decrypt the authentication cookie. Since the existing cookie cannot be decrypted the user is deemed unauthorized and needs to login again.

要解决此问题,您可以手动设置

To overcome this you can manually set the machine key in the applications web.config

Developer Fusion 提供了一个很好的在线工具,可以为您生成这些工具.下面是一个示例...

There is a good online tool by Developer Fusion which can generate these for you. Below is an example of one...

<machineKey 
  validationKey="B4A19ABE93A27433785DD47D6444E4B59394E220641D339AEE453D701F202140FF2BF519CED40335A0563AFB494A48DDF1A8DA00D462B42813712D21342B28C2"
  decryptionKey="2488146C1EA8177EB75422FE6FB6188550EBD0E4B67FCFD33056E50AD9771040"
  validation="SHA1" decryption="AES"

/>

现在,每次重新部署密钥时都不会更改.

Now everytime you redeploy the keys never change.

希望这会有所帮助.

这篇关于部署后ASP.NET Identity 2重新登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆