Hi,
I'm working on my "last resort" error block for a web application.
If the error occurs after a Request has been made, I want to show the URL.
If the Request object is not available, I'll skip it.
I thought I could check for the existence of an object by comparing to null.
However, in the global.asax code below, the "if (Request == null)" line
throws the error "Request is not available in this context".
Is there a way to check whether Request is available before referencing it?
Thanks,
Mark
protected void Application_Start(object sender, EventArgs e)
{
throw new Exception(); // test getting an error before a page
displays
}
protected void Application_Error(object sender, EventArgs e)
{
Exception exc = Server.GetLastError().GetBaseException();
string message;
if (Request == null)
{
message = "Unhandled error caught in Application_Error event
as a last resort" +
"\nError Message:" + exc.Message.ToString();
}
else
{
message = "Unhandled error caught in Application_Error event
as a last resort" +
"\nError on Page: " + Request.Url.ToString() +
"\nError Message:" + exc.Message.ToString();
}
// Display and/or log message
}