views:

5349

answers:

3

I have a site where I use CustomErrors in the web.config to specify a custom error page, and that's working just fine. The custom 404 page is also specified in the IIS configuration (because if it's not, I don't get my custom 404 page).

But I have some logic that kicks in if a user gets a 404 that looks at their requested URL and make a navigation suggestion, if appropriate. This logic relies on the aspxerrorpath value. On my development PC, the aspxerrorpath is correctly appended to the URL, like so: http://localhost:3092/FileNotFound.aspx?aspxerrorpath=/badpage.aspx, but on my test site, there's no aspxerrorpath appended to the URL, so all of my custom logic is bypassed and my suggestions don't work. I'm not sure if this is an IIS config issue or something else. The web server is Windows Server 2008 with IIS 7.

Any thoughts?

Many Thanks.

+1  A: 

On the server, does it get redirected to FileNotFound.aspx or does the url stay the same when the error occurs?

Is there a value for defaultRedirect in the web.config? If you remove the values in that element, does the behavior change?

John Sheehan
Thanks John. More info:On the server, the URL stays the same (it does not go to FileNotFound.aspx).There is no defaultRedirect value in the web.config.
theog
+3  A: 

The aspxerrorpath parameter is passed if the error was caught by .NET (and the error page specified in web.config is used). This happens if you're using the development web server, or if IIS is configured not to check that the file exists.

If IIS checks that the file exists, then the custom error configured in IIS is used, and the requested URL is included in the querystring as something like

http://example.com/FileNotFound.aspx?404;http://example.com/badpage.aspx

stevemegson
+5  A: 

You may have to add the below to web.config

<customErrors mode="On">
  <error statusCode="404" redirect="~/error404.aspx" />
</customErrors>

For more information check : http://geekswithblogs.net/shahed/archive/2007/10/23/116278.aspx

Update: We can utilize the IIS7 functionality for displaying custom 404 error pages using HTTPModules as described in http://professionalaspnet.com/archive/2008/02/13/Enforcing-a-Custom-404-Page-in-ASP.NET.aspx

Ramesh
Thanks Ramesh. I do have this set in the web.config.
theog
@theog: Please let me know what non exisiting page you are trying to access in testing machine. Is it associated to aspnet worker process? Also, have a look at 404 HttpModule described in http://professionalaspnet.com/archive/2008/02/13/Enforcing-a-Custom-404-Page-in-ASP.NET.aspx
Ramesh