Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
697 views
in Technique[技术] by (71.8m points)

authentication - ASP.NET Identity 2 relogin after deploy

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

Imagine the scenario:

  • user logs in (standard auth cookie)
  • application is redeployed
  • user needs to relogin again.

Questions:

  1. Is it possible not to relogin after deploy?
  2. Sometimes, after deploy when you refreshes a page, that requires authorized access - it displays correctly, but if you refresh the second time - it redirects to login page.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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.

Hope this helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...