I have an InProc session website with the following implementation:
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();
}
}
I read a couple articles (1,2) on stack that go into details about using this.Session to get to get to HttpSessionState. What about Server.MapPath() and Request.ServerVariables()? I can't get these to work within Session_End either.
I pasted this same blob of code into a button_Click event and it runs without issues. This leads me to believe that it is something related to Session_End.
I setup IIS6 to recylcle once per minute. When I have an open session it blows up with:
Error:
Exception type: HttpException
Exception message: Server operation is not available in this context
In the event viewer it shows up as event 1309. It complains about the line containing Server.MapPath()