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

最后都变了- 提交于 2019-12-07 02:47:23

问题


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.


回答1:


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)



来源:https://stackoverflow.com/questions/12206012/why-do-i-have-unstable-session-in-a-mvc3-application-with-godaddy-servers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!