【发布时间】:2011-01-12 22:55:11
【问题描述】:
我有一个具有以下实现的 InProc 会话网站:
protected void Session_End(object sender, EventArgs e)
{
StreamWriter sw = null;
string logFile = Server.MapPath("testSessionLog.txt");
sw = new StreamWriter(logFile, true);
sw.WriteLine("Session_End called at " + DateTime.Now);
try
{
//Request is not available in this context
if (Request.ServerVariables["Logon_User"] != null && Request.ServerVariables["Logon_User"] != "")
{
sw.WriteLine("Made it past Request.ServerVariables check");
}
}
catch (Exception ex)
{
sw.Write("An error occured: " + ex.Message);
}
finally
{
sw.Close();
}
}
我在堆栈上阅读了几篇文章 (1,2),其中详细介绍了如何使用 this.Session 访问 HttpSessionState。 Server.MapPath() 和 Request.ServerVariables() 呢?我也无法让这些在 Session_End 中工作。
我将相同的代码块粘贴到 button_Click 事件中,它运行没有问题。这让我相信它与 Session_End 有关。
我将 IIS6 设置为每分钟循环一次。当我有一个公开会议时,它会爆发:
错误:
异常类型:HttpException
异常消息:服务器操作在此上下文中不可用
在事件查看器中,它显示为事件 1309。它抱怨包含 Server.MapPath() 的行
【问题讨论】: