Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I have unstable session in a MVC3 application with godaddy servers

I have a MCV3 application in godaddy serves and the session is quite unstable.

When I login it works fine but while navigating in the application it logs me out, and hitting refresh or navigating a little more inside the application in logs me in just like that (without asking credentials or anything). On my remote test servers and local in works fine.

like image 897
memeonline Avatar asked Aug 30 '12 21:08

memeonline


1 Answers

This is probably not a session issue but rather an authentication cookie/ticket issue. GoDaddy (most likely) has their servers load balanced. Meaning that your application actually exists on more than one server at a time.

In your web.config, if you are not properly defining the <machineKey> attribute, then IIS makes up a machine key for you. Each server running the application will make their own machine key if it is not defined by you. As a result, one server is able to decrypt and read your authentication ticket, while the next request goes to another server which cannot decrypt the authentication ticket because it was encrypted with a different key and this server thinks that you are not logged in.

To address this issue, open your web.config file and define your <machineKey> attribute and redeploy. Once you login with the newly deployed application, you should see this issue disappear.

Forms authentication and Machine Key information on MSDN

Machine Key Generator (Most likely, everyone going here should use the .NET 2.0 version that is generated)

like image 191
Tommy Avatar answered Sep 21 '22 15:09

Tommy