473,406 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

CheckVirtualFileExists

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(VirtualP ath virtualPath)
at
System.Web.Compilation.BuildManager.GetVPathBuildR esultInternal(VirtualPath
virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean
allowBuildInPrecompile)
at
System.Web.Compilation.BuildManager.GetVPathBuildR esultWithNoAssert(HttpContext
context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp,
Boolean allowBuildInPrecompile)
at
System.Web.Compilation.BuildManager.GetVirtualPath ObjectFactory(VirtualPath
virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert)
at
System.Web.Compilation.BuildManager.CreateInstance FromVirtualPath(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.IHttpH andlerFactory2.GetHandler(HttpContext
context, String requestType, VirtualPath virtualPath, String physicalPath)
at System.Web.HttpApplication.MapHttpHandler(HttpCont ext context, String
requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
at
System.Web.HttpApplication.MapHandlerExecutionStep .System.Web.HttpApplication.IExecutionStep.Execute ()
at System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously)
Aug 29 '07 #1
2 10388
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 (wa****@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.

Aug 30 '07 #2
Thanks Walter; That was it.

Sep 4 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Joel D. Kraft | last post by:
I've been very happy with the performance and new features of my site since we converted to ASP.NET 2.0 beta 2. I have noticed a couple of interesting problems, though, which I am trying to...
0
by: Vish | last post by:
Hi, We are having issues whenever we push the dynamically compiled .ascx files into prod. These are the files with no codebehind and what happens is that the old users see this error and the new...
0
by: Lucky | last post by:
hi guys! i've come across one error that i'm not able to understand. Scenerio: i'm using a file upload control to upload a file. <input type="file" id="tbFile" class="InputField" ...
0
by: Rasika WIJAYARATNE | last post by:
Hello everyone, We have a forum system on our website. The main web application is running in a virutal directory called /t7 and the forum system is on / t7/forums/. When someone wants to post...
0
by: dankyy1 | last post by:
hi ,i have an asp.net project runs on local intranet ,i use global.asax's onerror section to catch errors.so i got a simpleauth service does not exists error from some network clients .Error details...
5
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi everyone! I get some errors lately regarding: HTTP_USER_AGENT Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) and: ...
2
by: =?Utf-8?B?UGF1bCBCdXp6YSwgb2xkc3RlciB1c2luZyBuZXcg | last post by:
I recently implemented error processing on my .net website, where I send myself an email from global.asax on an application error. In the last two days I have gotten a "The file '/detail.aspx'...
0
by: KingKong07 | last post by:
Hi! I have a problem with publishing my solution. I use “Use fixed naming and single page assemblies” to publish. So I just can update one and one file, this works fine, but today I had to update...
16
by: tagg3rx | last post by:
Hi All, I recently implemented a global error catcher in my application that sends me an e-mail every time an error happens. One error I'm seeing regularly that I can't track down appears to have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.