HttpContext.Current.Session对象为null。 Application_Error事件中的异常。
protected void Application_Error(object sender, EventArgs e)
{
Exception ex = HttpContext.Current.Server.GetLastError();
if (ex.Message == "File does not exist." && HttpContext.Current.Session == null)
{
if (((System.Web.HttpException)(ex)).GetHttpCode() == 404)
{
LogtheException(Session["uname"].ToString());// Throwing the Exception Here
}
}
else
{
LogtheException(Session["uname"].ToString());
Server.Transfer(UrlMaker.ToError(ex.Message.ToString()));
}
}
抛出异常
Session state is not available in this context.
如果任何css / image文件路径不正确,为什么HttpContext.Current.Session对象为null。相反,它应该抛出FileNotFoundException并且还可以访问会话数据。