Why are my forms authentication tickets expiring so fast?

前端 未结 5 2145
鱼传尺愫
鱼传尺愫 2021-02-08 14:26

I\'m using forms authentication in an ASP.NET application. I configure the FormsAuthenticationTicket to expire in 1 year but it actually expires after 1 hour or so.

5条回答
  •  悲哀的现实
    2021-02-08 15:12

    This is your problem.

    
    

    ASP will generate a new machine key every time the app pool recycles. Which could reasonably happen every hour.

    The machine key is used to encrypt and decrypt your FormsAuthentication cookie. If it changes, the cookie on your browser is no longer any good. So the system will treat you as if you have never logged on.

    Try generating a static key and adding it to the configuration file. Should look something like this:

    
    

    Generate yourself a key here.

提交回复
热议问题