1
当应用程序抛出“文件不存在”时,HttpContext.Current.Session对象为null。 Application_Error事件中发生异常。为什么“文件不存在”。 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.
为什么HttpContext.Current.Session对象为空,如果任何CSS /映像文件的路径是不正确的时候。相反,它应该抛出FileNotFoundException并且还可以访问会话数据。