webfarm里共享session

You can use state server or SQL server to store the sessions. We choose SQL server in this case.

1. Set up SQL server, add a new database by running the script
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\InstallSqlState.sql
or
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\InstallPersistSqlState.sql

Difference:
The first one stores session data in tempdb, which is cleared after the sql server is restarted
the second one stores session data in its own database.

2. Change session state to SQL server, and use cookieless session (if u know how to use when cookie is used, pls inform me)

    <sessionState
            mode="SQLServer"
            stateConnectionString="tcpip=127.0.0.1:42424"
            sqlConnectionString="data source=eteamsdev;user=sa;password=123456"
            cookieless="true"
            timeout="20"
    />

3. Generate a machine key and add it to web.config
To generate a machine key, pls see here: http://www.eggheadcafe.com/articles/20030514.asp
<configuration>
  <system.web>
   <machineKey validationKey='423110A2D3793A370D080852CE1094AA340C30710560656834EFE9696BBF9222B2962A6370567BCC4993BA61737BD895DF2CA3A3C562936882E928E1427AE725'   decryptionKey='AA4CE2B958A0C53F7FE2D6F1A8F7365924E444E0072C3BE3'   validation='SHA1'/>

4. Now deploy the website in two machines, and try:
http://machinea/websitea/a.aspx
save a session variable and display it
change to http://machineb/websitea/a.aspx
the session variable shoudl appear there too.

if not, check the database to see if the session id are the same, and check the application path using adsutil (C:\Inetpub\AdminScripts\adsutil.vbs).

posted on 2005-05-26 14:33  myrat  阅读(819)  评论(0编辑  收藏  举报

导航