//注意,需要引用System.Runtime.Serialization.Formatters.Soap.dll程序集
public const string SESSIONDATAPATH = @"C:/SessionData/" ;
private void Application_AcquireRequestState( object sender, EventArgs e)
{
System.IO.FileStream fs;
System.Runtime.Serialization.Formatters.Soap.SoapFormatter sf = new System.Runtime.Serialization.Formatters.Soap.SoapFormatter();
try
{
//获取特定的cookie,如果找不到,则退出.
HttpCookie cookie = Request.Cookies["PermSessionID"];
if(cookie == null)
{
//如果找不到,则生成一个(使用伪随机的SessionID)
cookie = new HttpCookie("PermSessionID", Session.SessionID);
//使该cookie在1星期之后到期
cookie.Expires = DateTime.Now.AddDays(7);
//将其发往客户端浏览器
Response.Cookies.Add(cookie);
}
//文件名等于该cookie的值
string permSessionId = cookie.Value;
//生成数据文件的名称
string filename = SESSIONDATAPATH + permSessionId.ToString() + ".xml";
//打开文件,如果出错,则退出
fs = new System.IO.FileStream(filename, IO.FileMode.Open);
//反序列化包含值的Hashtable Hashtable ht = (Hashtable)sf.Deserialize(fs);
//将数据移到Session集合中
Session.Clear();
foreach( string key in ht.Keys )
{
Session(key) = ht(key);
}
}
Catch(Exception ex) {}
Finally
{
if( fs != null ) fs.Close();
}
}
以上代码实现了会话持久话的过程,AquireRequestState事件处理程序中的代码会试图读取一个名为PermSessionID的特殊的客户端cookie。该cookie的值被视为一个XML(在服务器上)的名称,该XML文件包含在前一个请求结束时保存下来的Session变量的值,因此代码会在页面看到新值之前填充Session集合。如果该cookie尚不存在,说明现在看到的是从客户端发出的第一个请求。所以代码会创建cookie,并在其内部存放独一无二的字符串。同时也应该在ReleaseRequestState事件里创建一个服务端的XML文件,将所有Session变量序列化到该XML文件中。
分享到:
相关推荐
IIS%2bWordPress利用UrlRewrite实现永久链接-Permanent-Links-的完美方案
for hrush less permanent-niaghei motors ever It is dcnigncd to sent the modern computer based generation of mo;or engineers, '['he book. uoe» hand-in-hand with modern software-based tedwiquer- for ...
Control of Permanent Magnet Synchronous Motors Sadegh Vaez-Zadeh (作者) pages:357
Books on permanent magnet (PM) ac machine drives have focused primarily on the design of the machines and have covered the control and converters for these drives only in an elementary manner. In ...
Edward Snowden - Permanent Record-Metropolitan Bo(1).pdf
Permanent magnet synchronous generator modeling
A new rotor structure for line start permanent magnet synchronous moto
Induction versus permanent magnet motors
1.0前言摘要2.0 Permanent Ecological 简明概述3.0 Permanent Ecological 核心技术概述3.1 Tendermin
Analysis of Torque in Permanent Magnet.pdf
永磁同步电机的鲁棒控制器设计,邓镇华,年晓红,永磁同步电动机被广泛的应用到各个领域。相比于传统的感应电机它有着诸多的有点,例如,功率因数更高。随着制造工艺的提升,在未来,��
1.0前言摘要2.0 Permanent Ecological 简明概述3.0 Permanent Ecological 应用生态概述3.1 云算力轻客户端3.
An advanced introduction to the simulation and hardware implementation of BLDC motor drives A thorough reference on the simulation and hardware implementation of BLDC motor drives, this book covers ...
control of synchronous permanent magnet motor
一种永磁同步电机弱磁新方案,寇宝泉,李春艳,针对传统永磁同步电机在弱磁运行方面的不足,提出了一种跟随电机转速自动弱磁的新型永磁同步电机结构。介绍了该电机的弱磁原理。
how to control a permanent magnet synchron motor
永磁同步直线电机模型,已搭建完成,对初学者有帮助
MATLAB SIMULATION OF PERMANENT MAGNET SYNCHRONOUS MOTOR : To Control Speed of a Permanent Magnet Synchronous Motor by using MATLAB/SIMULINK
Optimum Design of a Five-phase Permanent Magnet Synchronous Motor for Underwater Vehicles by use of Particle Swarm Optimization