Monday, December 22, 2008
Recovering the Missing
Under IIS 5.0 and before, and when debugging under Visual Studio 2005, HTTP file-not-found errors can be caught in a global.asax Application_Error event function, obscurely documented by Microsoft, whose first argument can be cast to global_asax, which supplies context, including an error message but not an HTTP error code. By using Server.Transfer error handling can be redirected to an ASP.NET page.
Microsoft documentation for Visual Studio 2005 does not explain how to catch HTTP file-not-found errors under IIS 6.0, and many of the contributors to forums and Web logs have spread misinformation. IIS 6.0 will redirect HTTP file-not-found errors when configured for Custom Errors: HTTP Error 404, Type URL and Contents a so-called "absolute URL" for an ASP.NET page, for example, /VirtualDirectory/ErrorHandler.aspx where ErrorHandler.aspx.cs provides code to handle the file-not-found error.
The key to this approach, omitted from Microsoft documentation, is that Request.RawUrl in the code for the error handler page identifies the HTTP error and provides the original URL that provoked it. It has the format, ErrorHandlerURL?nnn;OriginalURL, where ErrorHandlerURL is the URL to reach the error handler page, nnn is the HTTP error code, and OriginalURL is the URL that provoked the HTTP error. An error handler page can set Response.ContentType and write to the Response.Output stream to supply content for the OriginalURL.
Microsoft documentation for Visual Studio 2005 does not explain how to catch HTTP file-not-found errors under IIS 6.0, and many of the contributors to forums and Web logs have spread misinformation. IIS 6.0 will redirect HTTP file-not-found errors when configured for Custom Errors: HTTP Error 404, Type URL and Contents a so-called "absolute URL" for an ASP.NET page, for example, /VirtualDirectory/ErrorHandler.aspx where ErrorHandler.aspx.cs provides code to handle the file-not-found error.
The key to this approach, omitted from Microsoft documentation, is that Request.RawUrl in the code for the error handler page identifies the HTTP error and provides the original URL that provoked it. It has the format, ErrorHandlerURL?nnn;OriginalURL, where ErrorHandlerURL is the URL to reach the error handler page, nnn is the HTTP error code, and OriginalURL is the URL that provoked the HTTP error. An error handler page can set Response.ContentType and write to the Response.Output stream to supply content for the OriginalURL.
Comments:
<< Home
Asp.Net Tutorial
Introducing Web Portals and Dropthings.com
Defining a Web Portal
Defining a Web 2.0 Portal
Using a Web Portal
Navigating Dropthings
Using ASP.NET AJAX
Using C# 3.0 and .NET 3.5
Architecting the Web Portal and Widgets
Using a Widget Framework
Adding Widgets
Maximizing the First-Visit Experience
Rendering a Second-Visit Experience
Improving ASP.NET AJAX Performance
Adding Authentication and Authorization
Post a Comment
Introducing Web Portals and Dropthings.com
Defining a Web Portal
Defining a Web 2.0 Portal
Using a Web Portal
Navigating Dropthings
Using ASP.NET AJAX
Using C# 3.0 and .NET 3.5
Architecting the Web Portal and Widgets
Using a Widget Framework
Adding Widgets
Maximizing the First-Visit Experience
Rendering a Second-Visit Experience
Improving ASP.NET AJAX Performance
Adding Authentication and Authorization
Subscribe to Post Comments [Atom]
<< Home
Subscribe to Posts [Atom]