我使用ASP.Net + .Net 3.5 + VSTS 2008 + IIS 7.0 + C#开发Web应用程序。我正在创建一个非常简单的Web应用程序,并且我只是修改了page_load,Session_Start和Session_End。这里是我的代码,我的问题是我发现会话开始消息后会话结束消息立即写入文件。我的测试方法只是打开IE访问此页面。我认为会议应该持续很长时间,就像几分钟。为什么会话如此快速结束?即使我没有关闭该页面,为什么还是会结束?ASP.Net会话开始和结束问题
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("Hello World! ");
Session["SomeUserData"] = DateTime.Now;
}
protected void Session_Start(object sender, EventArgs e)
{
using (TextWriter tw = new StreamWriter(@"C:\TestSession\bin\session.txt", true))
{
// write a line of text to the file
tw.WriteLine(DateTime.Now + " Session Started.");
}
}
protected void Session_End(object sender, EventArgs e)
{
using (TextWriter tw = new StreamWriter(@"C:\TestSession\bin\session.txt", true))
{
// write a line of text to the file
tw.WriteLine(DateTime.Now + " Session Ended.");
}
}
我见了即使添加会话操作代码到Page_Load方法同样的问题,这里是输出文件的内容,你可以看到会话结束事件会话开始后立即调用。
2010/7/15 0:11:14 Session Started.
2010/7/15 0:11:14 Session Ended.
2010/7/15 0:11:28 Session Started.
2010/7/15 0:11:28 Session Ended.
由于事先 乔治
http://msdn.microsoft.com/en-us/library/system.web.sessionstate.sessionstatemodule.end.aspx – 2010-07-11 17:32:46
你想从这个链接证明什么? – George2 2010-07-12 18:26:49