为什么在带有Godaddy服务器的MVC3应用程序中会话不稳定 [英] Why do I have unstable session in a MVC3 application with godaddy servers

查看:38
本文介绍了为什么在带有Godaddy服务器的MVC3应用程序中会话不稳定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在godaddy服务中有一个MCV3应用程序,会话非常不稳定.

当我登录时,它运行良好,但是在应用程序中导航时,它会将我注销,然后按刷新或在应用程序中导航更多时,将使我登录(无需询问凭据或其他内容).在我的远程测试服务器和本地测试服务器上都可以正常工作.

解决方案

这可能不是会话问题,而是身份验证Cookie/票证问题. GoDaddy(最有可能)使其服务器负载平衡.这意味着您的应用程序实际上一次存在于多个服务器上.

在您的web.config中,如果没有正确定义<machineKey>属性,则IIS将为您创建一个机器密钥.如果您未定义,则运行该应用程序的每个服务器都会创建自己的机器密钥.因此,一台服务器可以解密并读取您的身份验证票,而下一个请求将转到另一台服务器,该服务器无法解密该身份验证票,因为它已使用其他密钥加密,并且该服务器认为您尚未登录. /p>

要解决此问题,请打开您的web.config文件并定义您的<machineKey>属性并重新部署.使用新部署的应用程序登录后,您应该会看到此问题消失.

MSDN上的表单身份验证和计算机密钥信息

机器密钥生成器(很可能,每个人都应该使用.NET 2.0生成的版本)

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.

解决方案

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)

这篇关于为什么在带有Godaddy服务器的MVC3应用程序中会话不稳定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆