asp.net mvc - Cookie expires or session timeout too soon -


I have code that is run when user is authorized:

  FormsAuthenticationTicket authTicket = New form authenticationTicket (1, email, date time.Now, date time.Now additional minutes (120), true, userdata); String Encaket = Formatting. Encrypt (authTicket); HttpCookie faCookie = New HttpCookie (form authentication.formcookname, encrypt); FaCookie.Expires = authTicket.Expiration; Response.Cookies.Add (faCookie);   

Then I redirect to an Administrator / Action that has the Authorization feature:

  [Authorized] Public class Product Controller: Controller {  

I have the web The config has the following:

  & lt; Authentication mode = "form" & gt; & Lt; Form log in url = "~ / home / unauthorized" timeout = "2880" /> & Lt; / Authentication & gt; & Lt; sessionState timeout = "120" & gt; & Lt; / SessionState & gt;   

Although the users are complaining of the session deadline or after a few minutes of inactivity, the home / unauthorized redirects are done.

What can be done with it, what else should I check?

Before I'm expiring your login time, before going into a possible solution Ideas First, the formification cookie and session place are two completely different things completely completely. You may not have one or the other, or both, or consequently, the expiration for these two items is also not related.

The FormsAuthentication cookie is an encrypted cookie that contains some basic information such as usernames and end values A user has been certified to find out if the user is authorized for some resources or not, then this cookie uses this cookie.

What is the encryption and decryption of the form accreditation cookie for that web application on IIS. There is a set of keys used to encrypt and decrypt machine's cookie by default, on IIS A web application is set to automatically generate the key of the machine. This means that when an app starts, a random machine key is generated. If an app is recycle, you get the key of a new machine. In addition, if you are hosting on a shared provider, then the web host will usually balance your app load, which means more than one server is hosted. Each of those servers will automatically generate a machine key.

If your web application is on a loaded landscape, then each machine in the web field can not decrypt another's encrypted cookie, it will present the presence of "log out". The example of this is logging on Web Server A, then a subsequent request goes to the web server. Web server B does not share a machine key with Web server A and can not decrypt the cookie, the user can be sent back to the login page.

Solutions Your Web To define the mechanism of the machine in config, so will use the same key of each instance of the IIS and recycle the application pool as well, even if you have the same machine key. >

Here is one that you can put in your web.config

  & lt; System.web & gt; & Lt; machineKey validationKey = "EBC1EF196CAC273717C9C96D69D8EF314793FCE2DBB98B261D0C7677C8C7760A3483DDE3B631BC42F7B98B4B13EFB17B97A122056862A92B4E7581F15F4B3551" decryptionKey = "5740E6E6A968C76C82BB465275E8C6C9CE08E698CE59A60B0BEB2AA2DA1B9AB3" validation = "SHA1" decryption = "AES" / & gt; & Lt; /system.web> The additional consideration is that your web (120) do not match for your termination in conif (2880) and to actually set the duration of the closing. You want them to match both.   

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -