Address: http://www.itivy.com/ivy/archive/2011/4/24/634392360221984930.html
Create a class library project and add the following classes:
Using System. Web;
Using System;
Using System. Configuration;
Using System. Diagnostics;
Using System. Reflection;
Using System. Web. SessionState;
Namespace WebLibrary
{
Public class CrossDomainCookie: IHttpModule
{
Private string m_RootDomain = string. Empty;
# Region IHttpModule Members
Public void Dispose ()
{
}
Public void Init (HttpApplication context)
{
M_RootDomain = ConfigurationManager. deleettings ["RootDomain"];
Type stateServerSessionProvider = typeof (HttpSessionState). Assembly. GetType ("System. Web. SessionState. OutOfProcSessionStateStore ");
FieldInfo uriField = stateServerSessionProvider. GetField ("s_uribase", BindingFlags. Static | BindingFlags. NonPublic );
If (uriField = null)
Throw new ArgumentException ("UriField was not found ");
UriField. SetValue (null, m_RootDomain );
Context. EndRequest + = new System. EventHandler (context_EndRequest );
}
Void context_EndRequest (object sender, System. EventArgs e)
{
HttpApplication app = sender as HttpApplication;
For (int I = 0; I <app. Context. Response. Cookies. Count; I ++)
{
App. Context. Response. Cookies [I]. Domain = m_RootDomain;
}
}
# Endregion
}
}
Compile it into a dll.
Then, do the following in each website project that requires session sharing:
1. reference the above dll
2. Add your main site domain name to the appsetting node of web. config.
<Add key = "RootDomain" value = ".itivy.com"/>
3. Add the following content to the system. web node of web. config:
<HttpModules>
<Add name = "CrossDomainCookieModule" type = "WebLibrary. CrossDomainCookie, WebLibrary"/>
</HttpModules>
4. On the system. web node of web. config, change the session storage mode to stateserver.
<SessionState mode = "StateServer" stateConnectionString = "tcpip = 127.0.0.1: 42424" timeout = "30"/>
5. Add the following content to system. webServer of web. config:
<Modules>
<Add name = "CrossDomainCookieModule" preCondition = "managedHandler" type = "WebLibrary. CrossDomainCookie, WebLibrary"/>
</Modules>