我使用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