Session过期问题

SessionState 的Timeout),其主要原因有三种。
一:有些杀病毒软件会去扫描您的Web.Config文件,那时Session肯定掉,这是微软的说法。
二:程序内部里有让Session掉失的代码,及服务器内存不足产生的。
三:程序有框架页面和跨域情况。
第一种解决办法是:使杀病毒软件屏蔽扫描Web.Config文件(程序运行时自己也不要去编辑它)
第二种是检查代码有无Session.Abandon()之类的。
第三种是在Window服务中将ASP.NET State Service 启动。

http://community.csdn.net/Expert/topic/3100/3100218.xml?temp=.4426386
还有可能就是你在测试期间改动了,网站的文件。

我测试过没有问题!测试程序如下:
protected void Application_Start(Object sender, EventArgs e)
??{
???SqlConnection con = new SqlConnection("server=localhost;database=YourDatabase;uid=sa;pwd=;");
???SqlCommand cmd = new SqlCommand(string.Format("insert into table1 (c) values('{0}')","Application_Start"+DateTime.Now.ToLongTimeString()+"application id"+Application.ToString()),con);
???con.Open();
???cmd.ExecuteNonQuery();
???con.Close();

??}
?
??protected void Session_Start(Object sender, EventArgs e)
??{
???SqlConnection con = new SqlConnection("server=localhost;database=YourDatabase;uid=sa;pwd=;");
???SqlCommand cmd = new SqlCommand(string.Format("insert into table1 (c) values('{0}')","Session_Start"+DateTime.Now.ToLongTimeString()+"SessionID="+Session.SessionID),con);
???con.Open();
???cmd.ExecuteNonQuery();
???con.Close();


??}

??protected void Application_BeginRequest(Object sender, EventArgs e)
??{
???SqlConnection con = new SqlConnection("server=localhost;database=YourDatabase;uid=sa;pwd=;");
???SqlCommand cmd = new SqlCommand(string.Format("insert into table1 (c) values('{0}')","Application_BeginRequest"+DateTime.Now.ToLongTimeString()),con);
???con.Open();
???cmd.ExecuteNonQuery();
???con.Close();

??}

??protected void Application_EndRequest(Object sender, EventArgs e)
??{
???SqlConnection con = new SqlConnection("server=localhost;database=YourDatabase;uid=sa;pwd=;");
???SqlCommand cmd = new SqlCommand(string.Format("insert into table1 (c) values('{0}')","Application_EndRequest"+DateTime.Now.ToLongTimeString()),con);
???con.Open();
???cmd.ExecuteNonQuery();
???con.Close();

??}

??protected void Application_AuthenticateRequest(Object sender, EventArgs e)
??{

??}

??protected void Application_Error(Object sender, EventArgs e)
??{

??}

??protected void Session_End(Object sender, EventArgs e)
??{
???SqlConnection con = new SqlConnection("server=localhost;database=YourDatabase;uid=sa;pwd=;");
???SqlCommand cmd = new SqlCommand(string.Format("insert into table1 (c) values('{0}')","Session_End"+DateTime.Now.ToLongTimeString()+"SessionID="+Session.SessionID),con);
???con.Open();
???cmd.ExecuteNonQuery();
???con.Close();


??}

??protected void Application_End(Object sender, EventArgs e)
??{
???SqlConnection con = new SqlConnection("server=localhost;database=YourDatabase;uid=sa;pwd=;");
???SqlCommand cmd = new SqlCommand(string.Format("insert into table1 (c) values('{0}')","Application_End"+DateTime.Now.ToLongTimeString()),con);
???con.Open();
???cmd.ExecuteNonQuery();
???con.Close();


??}

所有的代码都是Global里面的

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值