void context_Error(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
Exception lastError = app.Server.GetLastError();
HttpException he = lastError as HttpException;
// handling only HttpExceptions (and 404 in particular):
if (he != null)
{
int httpErrorCode = he.GetHttpCode();
if (httpErrorCode == 404)
{
// clearing the error in order to avoid the exception to be thrown:
app.Server.ClearError();
String fofPage = H3Config.GetKeyAsString("Error404Page", "", "Argentini.Halide");
// setting/changing the handler for the current response:
app.Context.Handler = System.Web.UI.PageParser.GetCompiledPageInstance(fofPage, app.Server.MapPath(fofPage), app.Context);
}
}
}