本地虚拟2个域名测试多网站session共享功能,可是一直失败,下面是代码,望各位大侠帮看看
=================
一、以下是web.config中设置:
1、
<appSettings>
        <add key="RootDomain" value=".test.com"/>
2、
<httpModules>
        <add name="MakeSessionIDOneOnly" type="SessionShare.MakeSessionIDOneOnly, SessionShare"/>3、
<machineKey decryptionKey="FD69B2EB9A11E3063518F1932E314E4AA1577BF0B824F369" validationKey="5F32295C31223A362286DD5777916FCD0FD2A8EF882783FD3E29AB1FCDFE931F8FA45A8E468B7A40269E50A748778CBB8DB2262D44A86BBCEA96DCA46CBC05C3" validation="SHA1" decryption="Auto"/>

4、
<sessionState cookieless="false" timeout="50" mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424"/>5、
<system.webServer>
<modules>
<add name="MakeSessionIDOneOnly" preCondition="managedHandler" type="SessionShare.MakeSessionIDOneOnly, SessionShare"/>
</modules>
</system.webServer>二、SessionShare.dll文件代码
namespace SessionShare
{
    public class MakeSessionIDOneOnly : IHttpModule
    {
        private string m_RootDomain = string.Empty;        #region IHttpModule Members        public void Dispose()
        {        }        public void Init(HttpApplication context)
        {
            m_RootDomain = ConfigurationManager.AppSettings["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++)
            {
                if (app.Context.Response.Cookies[i].Name == "ASP.NET_SessionId")
                {
                    app.Context.Response.Cookies[i].Domain = m_RootDomain;
                }
            }
        }        #endregion
    }
}三、本地设置:在“C:\WINDOWS\system32\drivers\etc\hosts”中加2条记录
127.0.0.1       www.test.com
127.0.0.1       one.test.com=======================