使用ASP丢失会话状态。NET/SQL服务器

时间:2022-06-28 01:45:15

I have a ASP.NET MVC workflow configured as two websites managed by a load balancer. The websites use Sql Server as the session state provider and have authentication switch off (its not required).

我有一个ASP。NET MVC工作流配置为两个由负载均衡器管理的网站。这些网站使用Sql Server作为会话状态提供程序,并关闭身份验证开关(这不是必需的)。

Now, sporadically I appear to be losing session state, and I believe this is because the request is being handled by the alternative server, so essentially the user is jumping from server to server, depending how the load balancer sees fit. I am not always "losing session state" at the same stage in the workflow, so I believe it is something related to the web farm configuration + sql server session state.

现在,我偶尔会失去会话状态,我认为这是因为请求是由备用服务器处理的,因此用户从服务器跳到服务器,这取决于负载均衡器认为合适的方式。我并不总是在工作流的同一阶段“丢失会话状态”,所以我认为这与web farm配置+ sql server会话状态有关。

Both applications use the same machine key to encrypt and decrypt session state stored in sql server.

两个应用程序都使用相同的机器密钥来加密和解密存储在sql server中的会话状态。

The configuration on both servers is as follows:

两台服务器的配置如下:

<authentication mode="None" />
<sessionState mode="SQLServer" sqlConnectionString="{connection-string}" />
<machineKey decryptionKey="777CB456774AF02F7F1AC8570FAF31545B156354D9E2DAAD" 
            validationKey="89B5B536D5D17B8FE6A53CBB3CA8B8695289BA3DF0B1370BC47D362D375CF91525DDB5307D8A288230DCD4B3931D23AED4E223955C45CFF2AF66BCC422EC7ECD" />

I've confirmed that this is identical on both servers, is there something I am missing?

我已经确认这两个服务器都是一样的,有什么东西我遗漏了吗?

This does not occur in my development environment when I am using a single server.

当我使用一个服务器时,这种情况不会发生在我的开发环境中。

I fear I am suffering from the Friday blues, and no doubt will figure out the answer next week, sadly I don't want to wait!

我担心我患上了周五的忧郁症,毫无疑问会在下周找到答案,可惜我不想等!

Any ideas?

什么好主意吗?

3 个解决方案

#1


28  

Found the issue.

发现这个问题。

When you create applications that you expect to share session state using Sql Server, they need the same ID configured in IIS. This is because the session ID that is generated is generated based on the application ID. (Internally the application ID is something like LM/W3SVC/1

当您创建希望使用Sql Server共享会话状态的应用程序时,它们需要在IIS中配置相同的ID。这是因为生成的会话ID是基于应用程序ID生成的(在内部,应用程序ID类似于LM/W3SVC/1

The two servers had different IDs for each application in IIS. The resolution is to change the ID under `Manage Website -> Advanced Settings' on each server.

这两个服务器在IIS中的每个应用程序都有不同的id。解决方案是在每个服务器上更改“管理网站->高级设置”下的ID。

使用ASP丢失会话状态。NET/SQL服务器

#2


8  

  1. Using IIS Manager, double-check your machine key settings at both the root and website levels.
  2. 使用IIS管理器,在根和网站级别上双击您的机器键设置。

使用ASP丢失会话状态。NET/SQL服务器

  1. Review the IsolateApps modifier on the machine key element - http://msdn.microsoft.com/en-us/library/w8h3skw9%28v=vs.100%29.aspx

    查看机器关键元素上的IsolateApps修改器——http://msdn.microsoft.com/en-us/library/w8h3skw9%28v=vs.100%29.aspx

  2. Did you recently upgrade from 3.5 to 4.0?

    你最近有没有从3.5升级到4.0?

  3. Last resort - recycle the appPools on both machines, and restart IIS.

    最后一招——回收两台机器上的appPools,重新启动IIS。

#3


6  

Sessions have (web) application scope. See if this MS KB helps.

会话具有(web)应用范围。看看这个KB是否有帮助。

Update: Interesting down vote. Perhaps my suggestion needs more clarity.

更新:有趣的投票。也许我的建议需要更明确些。

In addition to matching machine keys, you also have to match the IIS configuration for sites (so it's the "same application" (application path) in IIS.

除了匹配机器键之外,还必须匹配站点的IIS配置(因此它是IIS中的“相同应用程序”(应用程序路径)。

#1


28  

Found the issue.

发现这个问题。

When you create applications that you expect to share session state using Sql Server, they need the same ID configured in IIS. This is because the session ID that is generated is generated based on the application ID. (Internally the application ID is something like LM/W3SVC/1

当您创建希望使用Sql Server共享会话状态的应用程序时,它们需要在IIS中配置相同的ID。这是因为生成的会话ID是基于应用程序ID生成的(在内部,应用程序ID类似于LM/W3SVC/1

The two servers had different IDs for each application in IIS. The resolution is to change the ID under `Manage Website -> Advanced Settings' on each server.

这两个服务器在IIS中的每个应用程序都有不同的id。解决方案是在每个服务器上更改“管理网站->高级设置”下的ID。

使用ASP丢失会话状态。NET/SQL服务器

#2


8  

  1. Using IIS Manager, double-check your machine key settings at both the root and website levels.
  2. 使用IIS管理器,在根和网站级别上双击您的机器键设置。

使用ASP丢失会话状态。NET/SQL服务器

  1. Review the IsolateApps modifier on the machine key element - http://msdn.microsoft.com/en-us/library/w8h3skw9%28v=vs.100%29.aspx

    查看机器关键元素上的IsolateApps修改器——http://msdn.microsoft.com/en-us/library/w8h3skw9%28v=vs.100%29.aspx

  2. Did you recently upgrade from 3.5 to 4.0?

    你最近有没有从3.5升级到4.0?

  3. Last resort - recycle the appPools on both machines, and restart IIS.

    最后一招——回收两台机器上的appPools,重新启动IIS。

#3


6  

Sessions have (web) application scope. See if this MS KB helps.

会话具有(web)应用范围。看看这个KB是否有帮助。

Update: Interesting down vote. Perhaps my suggestion needs more clarity.

更新:有趣的投票。也许我的建议需要更明确些。

In addition to matching machine keys, you also have to match the IIS configuration for sites (so it's the "same application" (application path) in IIS.

除了匹配机器键之外,还必须匹配站点的IIS配置(因此它是IIS中的“相同应用程序”(应用程序路径)。