.net主站和二级域名下实现session共享
2024-10-11 03:32:30
public class CrossDomainCookie : 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 = ; i < app.Context.Response.Cookies.Count; i++)
{
app.Context.Response.Cookies[i].Domain = m_RootDomain;
}
} #endregion
}
config里面配置:(注意两个站点都要配置)
<configuration>
<appSettings>
<add key="RootDomain" value=".session.com"/>
</appSettings>
<connectionStrings/>
<system.web>
<machineKey decryptionKey="FD69B2EB9A11E3063518F1932E314E4AA1577BF0B824F369" validationKey="5F32295C31223A362286DD5777916FCD0FD2A8EF882783FD3E29AB1FCDFE931F8FA45A8E468B7A40269E50A748778CBB8DB2262D44A86BBCEA96DCA46CBC05C3" validation="SHA1" decryption="Auto"/>
<sessionState cookieless="false" timeout="" mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424"/>
<httpModules>
<add name="CrossDomainCookieModule" type="WebLibrary.CrossDomainCookie, WebLibrary"/>
</httpModules>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
<!--
The system.webServer section is required for running ASP.NET AJAX under Internet
Information Services 7.0. It is not necessary for previous version of IIS.
-->
<system.webServer>
<modules>
<add name="CrossDomainCookieModule" preCondition="managedHandler" type="WebLibrary.CrossDomainCookie, WebLibrary"/>
</modules>
</system.webServer>
</configuration>
最新文章
- 【转】DBMS_STATS.GATHER_TABLE_STATS详解
- Message
- 2.PHP内核探索:一次请求的开始与结束
- ios blog
- App架构设计学习(一)---- 接口的设计
- 函数fsp_alloc_from_free_frag
- RTC搭建android下三层应用程序访问服务器MsSql-服务器端
- 通过使用CyclicBarrier来计算Matrix中最大的值
- 用户输出表单处理php
- 体验CSDN-Markdown
- [daily]gtk程序不跟随系统的dark主题
- [NOI2010]超级钢琴(RMQ+堆)
- python网络编程基础(线程与进程、并行与并发、同步与异步、阻塞与非阻塞、CPU密集型与IO密集型)
- 微信小程序实现简单的树形图treeview
- windows安装 centos
- wget命令的使用
- [POI2013]Polaryzacja
- 如何用dat批处理文件关闭某端口对应程序-Windows自动化命令
- 解决 Attempting to destroy the window while drawing!
- 【WPF】给UserControl引入多个资源