简体   繁体   English

在IIS8上的2个网站之间共享ASP.Net会话不起作用

[英]Sharing ASP.Net session between 2 websites on IIS8 does not work

I need to share asp.net session between 2 websites on same IIS. 我需要在同一IIS上的2个网站之间共享asp.net会话。

  • I created a custom session db and hijacked the stored procedure to return same appID regardless of app or url. 我创建了一个自定义会话数据库,并劫持了存储过程以返回相同的appID,而与app或url无关。

  • I created a connection string for the db in web.config: 我在web.config中为数据库创建了一个连接字符串:

< add name="dbConnSession" connectionString="server=xx.xxx.xx.xx.;database=ASPNETSession;User Id=xxx;Password=xxx" providerName="System.Data.SqlClient" /> <添加名称=“ dbConnSession” connectionString =“ server = xx.xxx.xx.xx .;数据库= ASPNETSession;用户ID = xxx;密码= xxx” providerName =“ System.Data.SqlClient” />

  • Then I defined session state: 然后我定义了会话状态:

< sessionState allowCustomSqlDatabase="true" cookieless="AutoDetect" mode="SQLServer" sqlCommandTimeout="10" sqlConnectionString="dbConnSession" timeout="120" sqlConnectionRetryInterval="2" /> <sessionState allowCustomSqlDatabase =“ true” cookieless =“ AutoDetect” mode =“ SQLServer” sqlCommandTimeout =“ 10” sqlConnectionString =“ dbConnSession” timeout =“ 120” sqlConnectionRetryInterval =“ 2” />

I developed the sites on my Win7 machine with IIS7 and login system works perfectly. 我使用IIS7在Win7机器上开发了站点,并且登录系统运行良好。 I can login from 1 site, go to other site and stay logged in. 我可以从1个站点登录,然后转到其他站点并保持登录状态。

I moved 2 sites into the web server (windows 2012 with IIS8.5) and the shared session does not work. 我将2个站点移到Web服务器(带有IIS8.5的Windows 2012)中,共享会话不起作用。 Sites simply does not share the session. 网站根本不共享会话。 I set a session value on one site and try to see it on the other and session value returns as null. 我在一个站点上设置了会话值,然后尝试在另一个站点上看到它,会话值返回为null。 The very same test page works on IIS7. IIS7上也可以使用相同的测试页。

Does anyone know why IIS8.5 has trouble with something works on IIS7? 有谁知道为什么IIS8.5在IIS7上无法正常工作?

You need to add a machine key that's the same to both web config files. 您需要为两个Web配置文件添加相同的机器密钥。

If goes in system.web and looks something like this: 如果进入system.web ,看起来像这样:

<machineKey validationKey="[your key]" decryptionKey="[dec key]" validation="SHA1" />

There are a few tools if you Google it that will create one for you. 如果您使用Google的话,有几种工具可以为您创建一个。

There are a few reasons why you need this key, mostly because the servers might have different paths to the folder where you code lies or different IIS settings. 之所以需要此键,有几个原因,主要是因为服务器在您的代码所在的文件夹中可能具有不同的路径或不同的IIS设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM