I'm trying to set it up so that when an error is thrown in my asp.net site, the resulting custom error page returns an identifier, which can be used to look an error up in the database.
The custom error page is set up in the web.config using the "customErrors" functionality.
<customErrors defaultRedirect="~/Error/error.aspx" mode="RemoteOnly">
<error statusCode="404" redirect="~/Error/error.aspx?status=404" />
</customErrors>
I'm currently bridging the gap using the session to pass along the id.
In Global.asax
protected void Application_Error(Object sender, EventArgs e)
{
Exception ex = HttpContext.Current.Server.GetLastError();
var errorCode = ExceptionManager.Publish(ex);
Session["ERROR_IDENTIFIER"] = errorCode;
}
In the CustomError page:
<%@ Page Language="C#" Debug="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Error Page</title>
<link href="/Error/css/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<%
string errorIdentifier = Session["ERROR_IDENTIFIER"] == null ? "this is null" : Session["ERROR_IDENTIFIER"].ToString();
Response.Write("There's been an error. Please send this identifier to service desk -> " + errorIdentifier);
%>
</body>
<html>
Unfortunately, what seems to happen in this workflow is that the customError page loads faster than the global.asax runs. Basically these are two distinct operations and they're being run separately, and I'd like to make it so that the custom error page has the correct Identifier in it.
Thanks, Alex