Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / September 2007

Tip: Looking for answers? Try searching our database.

CheckVirtualFileExists

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chuck P - 29 Aug 2007 20:56 GMT
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)
Walter Wang [MSFT] - 30 Aug 2007 09:12 GMT
Hi Chuck,

At that time in your HTTP module's Error handler, the Response.StatusCode
hasn't been set, which has the default value of 200.

To retrieve the http status code that caused the exception, you can check
for HttpException.GetHttpCode():

       HttpException ex = Server.GetLastError() as HttpException;
       if (ex != null)
       {
           int statusCode = ex.GetHttpCode();
       }

This should return 404 if the request path isn't found.

Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Chuck P - 04 Sep 2007 15:18 GMT
Thanks Walter;  That was it.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.