G
Guest
I have an asp.net application with a HttpModules in it.
It looks at:
AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(OnUhe); //UHE on threads
application.Error += new EventHandler(OnError); //regular UHE
When I put in a URL with a bad location I get an System.Web.HttpException
that is captured in my OnError method.
I would like to capture that this a 404 exception and display something
appropriate.
My HttpModule
has:
protected virtual void OnError(object sender, EventArgs args)
{
HttpApplication application = sender as HttpApplication;
Exception ex = application.Server.GetLastError() as Exception;
ProcessTheUHE(ex);
}
What's interesting though is that Application.Response.StatusCode=200, not
404. Is my HttpModule messing something up. Is there a reliable way to
identify that this is a 404?
thanks,
ex.Message
"The file '/Hr-AuthTest/Defaxult.aspx' does not exist."
STACK TRACE
at System.Web.UI.Util.CheckVirtualFileExists(VirtualPath virtualPath)
at
System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath
virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean
allowBuildInPrecompile)
at
System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext
context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp,
Boolean allowBuildInPrecompile)
at
System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath
virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert)
at
System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath
virtualPath, Type requiredBaseType, HttpContext context, Boolean
allowCrossApp, Boolean noAssert)
at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context,
String requestType, VirtualPath virtualPath, String physicalPath)
at
System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext
context, String requestType, VirtualPath virtualPath, String physicalPath)
at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String
requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
at
System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously)
It looks at:
AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(OnUhe); //UHE on threads
application.Error += new EventHandler(OnError); //regular UHE
When I put in a URL with a bad location I get an System.Web.HttpException
that is captured in my OnError method.
I would like to capture that this a 404 exception and display something
appropriate.
My HttpModule
has:
protected virtual void OnError(object sender, EventArgs args)
{
HttpApplication application = sender as HttpApplication;
Exception ex = application.Server.GetLastError() as Exception;
ProcessTheUHE(ex);
}
What's interesting though is that Application.Response.StatusCode=200, not
404. Is my HttpModule messing something up. Is there a reliable way to
identify that this is a 404?
thanks,
ex.Message
"The file '/Hr-AuthTest/Defaxult.aspx' does not exist."
STACK TRACE
at System.Web.UI.Util.CheckVirtualFileExists(VirtualPath virtualPath)
at
System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath
virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean
allowBuildInPrecompile)
at
System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext
context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp,
Boolean allowBuildInPrecompile)
at
System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath
virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert)
at
System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath
virtualPath, Type requiredBaseType, HttpContext context, Boolean
allowCrossApp, Boolean noAssert)
at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context,
String requestType, VirtualPath virtualPath, String physicalPath)
at
System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext
context, String requestType, VirtualPath virtualPath, String physicalPath)
at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String
requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
at
System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously)