views:

716

answers:

4

I have a situation where I want to catch 404 errors fired by HTML pages (not just aspx pages) but I only have access to the web.config of the root folder of my website, and all sub directories (note, i don't have access to the actual IIS server and I cannot create applications or change settings)

So I did try the web.config customerrors on a subdirectory, and they do work, for ASPX pages only, not HTML pages, does anyone know why?

A: 

HTML pages are not parsed by IIS therefore are not affected by web.config settings. I am not aware of any way around this without configuring the settings in IIS.

Jeremy
A: 

To be a bit more specific than what Jeremy said, IIS maps different file extensions to different executables. By default it will be configured to let the .NET runtime handle .aspx files (in which case your web.config will be loaded & used), but it will serve the .html pages directly itself (& therefore fall back on its own 404 error handling).

Annoying, but I don't think there's much you can do beyond either having control of IIS, or by making your flat html pages into aspx pages (even though they contain no actual server-side content), to trick IIS into letting .NET handle them.

Alconja
actually the pages dont exist, thats the whole point of catching 404 errors :)
Ayyash
Alconja
A: 

You could have a look at the new routing capabilities for ASP.NET: http://msdn.microsoft.com/en-us/library/cc668201.aspx.

knut
yes, there doesnt seem to be a better solution than this for now, thanks
Ayyash
+1  A: 

Note that the two answers above are correct for the usual case. However, IIS 6.0 and below can be configured to process HTML pages or anything else through ASP.NET. Also, IIS 7 has changed things radically - in effect, the ASP.NET pipeline is the IIS pipeline now, so that any piece of content is processed through any HttpModules.

Thus, in IIS 7 and above, anything you can configure for ASPX pages, you can configure for HTML pages.

John Saunders