I have this code in my web.config file:
<customErrors defaultRedirect="~/GeneralError.aspx" mode="On">
<error statusCode="401" redirect="401.aspx" />
<error statusCode="404" redirect="404.aspx" />
</customErrors>
This works perfectly on my local machine while running IIS and it redirects to my error pages, however when I run it on the server, IIS's default error pages pop in instead of mine.
Why is this? How can I fix this? Is this something related from the code, or is this some setting on the server?
This may not be the right solution for your issue, but double check IIS settings (Error Pages)
http://blogs.iis.net/rakkimk/archive/2008/10/03/iis7-enabling-custom-error-pages.aspx
IIS error pages settings override application config.
This format was working for me
<customErrors defaultRedirect="~/GeneralError.aspx" mode="On">
<error statusCode="401" redirect="~/GeneralError.aspx" />
<error statusCode="404" redirect="~/GeneralError.aspx" />
</customErrors>
or
<error statusCode="404" redirect="filenotfound.htm" />
Related
I am trying to get a message page to display a custom message if the visitor browses to a page eg. nothere.cshtml or to a none existing folder eg. /folder/nothere/
I would like to keep the url visible and not do a redirect
I have tried the following in system.web
<customErrors defaultRedirect="~/message.cshtml" mode="On" redirectMode="ResponseRewrite">
<error statusCode="404" redirect="~/message.cshtml" />
</customErrors>
And the following in system.webserver
<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/message.cshtml" responseMode="ExecuteURL" />
</httpErrors>
But I get a Server error in "/" application for a file and a standard 404 error message when browsing to a directory that do not exist.
I am able to make a custom error message using the normal responseRedirect but then the URL are not kept original
Anybody?
I have defined custom error pages in IIS (i.e for http status code 500) and they are working if I return status code 500 from controller. But if there is unhandled exception in application iis displays standard yellow page with status code 500. So I'd expect IIS to display my custom error page but it's not happening.
Is there any way to force IIS to display custom error page on exception?
You should add this into the web.config into <system.web> section:
<customErrors mode="On" defaultRedirect="~/path/to/error">
<error statusCode="413" redirect="~/path/to/error" />
...
...
</customErrors>
My advice is to do this only for the production environment, because the "yellow page" is extremely useful in dev mode to identity errors (for example you can add it only into web.release.config).
Inside <system.webServer> add
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="500" subStatusCode="-1" prefixLanguageFilePath="" path="/somePage.html" responseMode="Redirect" />
</httpErrors>
I've tried some ways to deploy my custom error page (e.g. error.aspx) onto my website:
Added customErrors: <customErrors mode="On"
defaultRedirect="error.aspx" />
Added httpError: <httpErrors>
<remove statusCode="404" subStatusCode="-1" /> <error
statusCode="404" prefixLanguageFilePath="" path="error.aspx"
responseMode="ExecuteURL" /> </httpErrors>
Currently, I can point this URL to my custom error page:
http://test.localdev.net/random_text.aspx
However, I failed for those kind of URL (unsupported extension), for these URLs IIS will use its own 404 page:
http://test.localdev.net/Default.random
Could anyone help me to fix it?
Thanks
are you using iis7 or later in integrated mode? Otherwise I think you need to configure error pages in iis itself.
Hay when i add defaultPath="/Error.aspx" to my web config i get an error that tells me that i have an error to my config. The problem is that without that all is going well with out errors. I have below some relevant settings:
<httpErrors defaultResponseMode="ExecuteURL" errorMode="Custom" existingResponse="Replace" >
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/Err.aspx" responseMode="ExecuteURL" />
</httpErrors>
<customErrors mode="On" defaultRedirect="~/Error.aspx" redirectMode="ResponseRewrite">
<error statusCode="404" redirect="~/Err.aspx" />
</customErrors>
Can you help me please. Do you know iis gives an error when i try to add a default path?
I was able to resolve this error only if I set setting "defaultPath" in file applicationHost.config of IIS.
Or you can set it with UI using next steps:
1) Open IIS
2) Select ServerName (not website)
3) Open menu "Error Pages"
4) Click "Edit Feature Setting" to the left.
5) Configure setting "Path" and other options in the popup.
I'm working on a personal website and I'm using webforms and .NET 3.5 and C#. I'm trying to get the custom error pages sorted but I can't get them to work properly. Not on my local IIS 7.5 as on the external server. It keeps prompting me with default IIS error pages when pages can't be found. How can it be fixed?
I've got the following section in my web.config file defining the errorpages;
<customErrors mode="RemoteOnly" defaultRedirect="~/ERRORPAGES/Default.aspx" redirectMode="ResponseRewrite">
<error statusCode="403" redirect="~/ERRORPAGES/Default.aspx" />
<error statusCode="404" redirect="~/ERRORPAGES/404.aspx" />
<error statusCode="400" redirect="~/ERRORPAGES/400.aspx" />
<error statusCode="500" redirect="~/ERRORPAGES/500.aspx" />
</customErrors>
Found out there was a problem with the server i was running. The host changed it and now online everything works as i expected it to be.