负载均衡下设置Session需要注意的一点,防止Session丢失
2009-03-26 09:47
330 查看
http://technet.microsoft.com/en-us/library/cc780248.aspx
Preserving Session State with ASP.NET Web Applications in Network Load Balancing
Updated: August 22, 2005
If you use SqlServer or StateServer session state mode, session state might be lost when you run an ASP.NET Web application in a Network Load Balancing server cluster. To maintain session state across different Web servers in the cluster, the application path of the Web site (for example, \LM\W3SVC\2) in the IIS metabase must be the same for all of the Web servers in the cluster.
On one Web server, the instance ID of the Web site where the ASP.NET application is hosted might be 1 (where the application path is \LM\W3SVC\1). On another Web server, the instance ID of the Web site might be 5 (where the application path is \LM\W3SVC\5).
负载均衡下需要把不同机器上站点的instance ID都设为同一个。否则session会丢失,即使你把session设为了保存在sqlserver。
需要运行如下脚本
MySitesIdList.vbs
Function ProcessWebSite(ServiceType, SiteNumber)
Set IISWebSite = getObject("IIS://localhost/" & ServiceType & "/" & SiteNumber)
Set IISWebSiteRoot = getObject("IIS://localhost/" & ServiceType & "/" & SiteNumber & "/root")
ProcessWebSite = IISWebSite.ServerComment
Set IISWebSiteRoot = nothing
Set IISWebSite = Nothing
end function
Function ShowSites(ServiceType, ClassName, Title)
Wscript.echo "Web Sites Description"
Wscript.echo "==============================================================="
Set IISOBJ = getObject("IIS://localhost/" & ServiceType)
for each Web in IISOBJ
if (Web.Class = ClassName) then
wscript.echo Ucase(ServiceType) & "/" & Web.Name & _
Space(17-(len(Ucase(ServiceType))+1+len(Web.Name))) & " " & _
ProcessWebSite(ServiceType, Web.name)
end if
next
Set IISOBj=Nothing
WScript.Echo ""
End function
Call ShowSites("w3svc", "IIsWebServer", "Web")
把脚本考到机器上然后运行cscript MySitesIdList.vbs
Dim WebService
Dim oldstr
Dim newstr
Dim args
Set args = WScript.Arguments
If args.Count < 1 Then
Wscript.Echo "Must have original instance id and new instance id" & chr(10) & chr(13) & _
"usage: moveinstance.vbs 1 5" & chr(10) & chr(13) & _
"Moves instance 1 to instance 5"
WScript.Quit()
End If
Set WebService = GetObject("IIS://LocalHost/W3SVC")
oldstr = args(0) 'old instance
newstr = args(1) 'new instance
WebService.MoveHere oldstr,newstr
WebService.SetInfo
Set WebService = nothing
Set args=nothing
WScript.echo "DONE"
运行
cscript ChangeSiteId.vbs 1 5
and then press ENTER. Instance ID就从1改到了5.
Preserving Session State with ASP.NET Web Applications in Network Load Balancing
Updated: August 22, 2005
If you use SqlServer or StateServer session state mode, session state might be lost when you run an ASP.NET Web application in a Network Load Balancing server cluster. To maintain session state across different Web servers in the cluster, the application path of the Web site (for example, \LM\W3SVC\2) in the IIS metabase must be the same for all of the Web servers in the cluster.
On one Web server, the instance ID of the Web site where the ASP.NET application is hosted might be 1 (where the application path is \LM\W3SVC\1). On another Web server, the instance ID of the Web site might be 5 (where the application path is \LM\W3SVC\5).
负载均衡下需要把不同机器上站点的instance ID都设为同一个。否则session会丢失,即使你把session设为了保存在sqlserver。
需要运行如下脚本
MySitesIdList.vbs
Function ProcessWebSite(ServiceType, SiteNumber)
Set IISWebSite = getObject("IIS://localhost/" & ServiceType & "/" & SiteNumber)
Set IISWebSiteRoot = getObject("IIS://localhost/" & ServiceType & "/" & SiteNumber & "/root")
ProcessWebSite = IISWebSite.ServerComment
Set IISWebSiteRoot = nothing
Set IISWebSite = Nothing
end function
Function ShowSites(ServiceType, ClassName, Title)
Wscript.echo "Web Sites Description"
Wscript.echo "==============================================================="
Set IISOBJ = getObject("IIS://localhost/" & ServiceType)
for each Web in IISOBJ
if (Web.Class = ClassName) then
wscript.echo Ucase(ServiceType) & "/" & Web.Name & _
Space(17-(len(Ucase(ServiceType))+1+len(Web.Name))) & " " & _
ProcessWebSite(ServiceType, Web.name)
end if
next
Set IISOBj=Nothing
WScript.Echo ""
End function
Call ShowSites("w3svc", "IIsWebServer", "Web")
把脚本考到机器上然后运行cscript MySitesIdList.vbs
Dim WebService
Dim oldstr
Dim newstr
Dim args
Set args = WScript.Arguments
If args.Count < 1 Then
Wscript.Echo "Must have original instance id and new instance id" & chr(10) & chr(13) & _
"usage: moveinstance.vbs 1 5" & chr(10) & chr(13) & _
"Moves instance 1 to instance 5"
WScript.Quit()
End If
Set WebService = GetObject("IIS://LocalHost/W3SVC")
oldstr = args(0) 'old instance
newstr = args(1) 'new instance
WebService.MoveHere oldstr,newstr
WebService.SetInfo
Set WebService = nothing
Set args=nothing
WScript.echo "DONE"
运行
cscript ChangeSiteId.vbs 1 5
and then press ENTER. Instance ID就从1改到了5.
相关文章推荐
- Poco 1.4.2 HTTPClientSession/HTTPRequest 使用使用代理(proxy)需要注意的一点
- 【转】Poco 1.4.2 HTTPClientSession/HTTPRequest 使用使用代理(proxy)需要注意的一点
- Apache+Tomcat负载均衡两种session共享方式的设置
- 需要注意属性设置和qss的冲突(ui编辑qss,代码设置属性出现冲突)
- GDI资源使用上需要注意的一点
- 把BufferedWriter和OutputStreamWriter连接起来时 注意最后需要使用flush()方法,以强制清空缓冲区中的剩余内容,防止遗露,
- Arcgis server 安装后配置需要注意的设置
- SharePoint的数据库性能需要注意的一点
- .net下导致Session失效的一种情况:js教本中使用window.open和window.showModalDialog时需要注意
- android ListView item 点击设置背景图片需要注意的问题
- 使用com.jayway.jsonpath.JsonPath包进行JSON的快速解析、设置值需要注意的性能提升方法
- Apache+Tomcat负载均衡两种session共享方式的设置之二复制会话
- 手机版网页设计html5元素meta name=”viewport”设置需要注意的地方
- 接近开关接线最需要注意的一点
- call()与apply()传参需要注意的一点
- 关于COOKIES需要注意的一点
- utf-8编码的网站,为了防止出现乱码,需要注意的相关事项
- .net下导致Session失效的一种情况:js教本中使用window.open和window.showModalDialog时需要注意
- 注意 IE iframe 中 Session 值的设置
- 使用ajax登录的时候设置session,刷新页面后session丢失