我在web.config里设置了timeout=2 但是2分钟后我的session依然存在没有注销,Session_End方法没有运行
用的IIS7 win2008系统 请教高手这是为何?
用的IIS7 win2008系统 请教高手这是为何?
解决方案 »
- 想学asp.net,请问有代码学习吗?请各位给推荐些,感激。
- 关于正则替换html标签~~~~~ 谢谢各位~ 回帖有分。。。
- cache不会过期
- 我用listbox显示数据表名称,我如何将“table1”改成“员工表”?
- 关于asp.net中 sql语句的请教
- vs2005调试不了。哪里有错误。?有图。大家帮助一下
- 请问怎么获得系统的当前用户名?怎么检查某个文件夹下是否存在文件,且只知道文件名的一部分,即模糊查询?
- asp.net网站莫名其妙的出现这样的问题...昨天还好用
- 英文高手帮帮忙,客户报告材料中要用到的材料~~~
- help!在线等
- WebServer 添加怎么不成功!
- 实体类是bool型如何在页面显示汉字?
那个 session 的 timeout 是干吗用的? 时间到了还需要另外一个请求、另外一个Session访问服务器才注销吗? 那我如何实现自动注销?
另外。你的iis要配置成经典模式
我不记得那一本入门书、或者msdn上明确讲解这个机制。但是我一旦跟别人讨论这个Session过期,都是基于asp.net的框架源代码的,上面的代码非常清晰易懂,每当当一个请求到达服务器的时候,服务器都会去检查有没有以前的Session需要做过期处理。因此,就算你设置为10分钟,也不是10分钟到点就过期,而是10分钟之后的第一次其它请求(包括本session的请求)到达服务器时,所有本来应该过期的session们才过期。
例如默认20分钟 你没有做任何动作。在刷新页面就会过期但是一旦在20分钟内做任何一个操作就会还有持续有效时间。
例如QQ的自动离开状态
你不操作电脑他就自动离开 而你一直在做任何操作QQ他就不会离开
我的是 Inproc模式 我的IIS也配置了经典模式 但是时间到了没有效果
我设置了 Inproc 但是没有效果
手动是什么意思? 手动清空cookie 那些的吗?
另外,你测试是否过期的方法是什么?
在过期之前,你是不能再访问这个站点的,否则,过期时间会往后推迟一个过期时间
我猜想是你更新数据库的错误导致的。Session_End事件里面只有Session.SessionID可用。其他的如Session["xxx"]是得不到的。你可以写成文件测试
void Session_End(object sender, EventArgs e)
{
System.IO.StreamWriter s = new System.IO.StreamWriter(HttpRuntime.AppDomainAppPath + "log.txt");
s.WriteLine("过期了 ");
s.Close();
}测试
如果Session["xxx"]得不到的话 我写了
Session.Clear();Session.RemoveAll();Session.Abandon();
然后在页面的Page_Load里写了Session["xxx"]判断 为空跳转页面 这个为什么没有作用?
{
Session["Lg_User"] = "";
Session.SessionID.ToString();
Session.Clear();
Session.RemoveAll();
Session.Abandon();
//}
System.IO.StreamWriter s = new System.IO.StreamWriter(HttpRuntime.AppDomainAppPath + "Sessionlog.txt");
s.WriteLine("过期了"+ Session.SessionID.ToString()+"----"+Session["Lg_User"]+" ");
s.Close();
}
{
if (!base.IsPostBack)
{
Unit unit = new Unit();
this.Label1.Text = "当前用户:" + MapgisEGov.User.User.GetUserName(this.Context);
this.Label2.Text = "所属部门:" + MapgisEGov.User.User.GetUserDeptName(this.Context);
this.Label3.Text = "上次登陆时间:";
this.Label4.Text = "累计登陆次数:";
DBAccess access = new DBAccess();
string strSql = "select LSLOADTIME , LOADCOUNT from USERLOGINFO where USERID ='" + MapgisEGov.User.User.GetUserCode(this.Context) + "'";
DataSet dataSet = access.GetDataSet(strSql);
if ((dataSet.Tables.Count > 0) && (dataSet.Tables[0].Rows.Count > 0))
{
this.Label3.Text = this.Label3.Text + dataSet.Tables[0].Rows[0]["LSLOADTIME"].ToString();
this.Label4.Text = this.Label4.Text + dataSet.Tables[0].Rows[0]["LOADCOUNT"].ToString();
}
}
if (base.Session["Lg_User"] == null || base.Session["Lg_User"].ToString().Equals(""))
{
Response.Write("<script>top.location.href='about:blank';</script>");
} else
{
Response.Write("<script>alert('"+Session["Lg_User"]+"');</script>");
}
Global.asax
<%@ Application Language="C#" %><script runat="server">
void Session_Start(object sender, EventArgs e)
{
} void Session_End(object sender, EventArgs e)
{
System.IO.StreamWriter s = new System.IO.StreamWriter(HttpRuntime.AppDomainAppPath + "Sessionlog.txt",true);
s.WriteLine( DateTime.Now.ToString() + " 过期了 " + Session.SessionID.ToString());
s.Close();
}
</script>
web,config
<?xml version="1.0"?>
<configuration>
<system.web>
<pages enableSessionState="true"/>
<sessionState mode="InProc" timeout="2"/>
<compilation debug="true" defaultLanguage="C#">
</compilation>
<globalization responseEncoding="utf-8"/>
</system.web>
</configuration>default.aspx
<%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(Session.Timeout);
if (!Page.IsPostBack)
{
Session["x"] = DateTime.Now.ToString();
}
} protected void Button1_Click(object sender, EventArgs e)
{
if (Session["x"] != null)
{
Response.Write(Session["x"].ToString());
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</form>
</body>
</html>
对于asp.net开发人员,口里所说的Session是指他在代码中使用到的那个Session集合,是具体的代码,而不是一些其它文章中的概念。对于这个Session集合代码而言,他有源代码,源代码比一些介绍文章岂不是更准确。
大侠,我读书时没好好读落得现在这下场,影响Session的可能性还有哪些啊? 请指点下吧
Session["Lg_User"] = "";
Session.SessionID.ToString();
Session.Clear();
Session.RemoveAll();
Session.Abandon();
都没有用
Session["Lg_User"]已经为null。你还s.WriteLine("过期了"+ Session.SessionID.ToString()+"----"+Session["Lg_User"]+" ");什么啊