IIS display standard yellow page instead of custom error page defined - c#

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>

Related

Custom error page is not displaying on IIS7 ASP.NET

I want to add custom error pages to my site. Firstly I have created a test web project, added two test pages, publish it to my local IIS and configured the web.config:
<configuration>
<system.web>
<compilation targetFramework="4.0" />
<customErrors mode="On" defaultRedirect="http://localhost:10000/apperror.aspx">
<error statusCode="404" redirect="http://localhost:10000/404.aspx" />
</customErrors>
</system.web>
I can browse this pages separately but when I try to access a not found page like:
http://localhost:10000/notfound.aspx
It works perfect and redirects to my error page. But when I try below
http://localhost:10000/notfound
IIS is showing his own error page not my custom error pages. I have searched but not found a solution, Could you please help me how can I achieve this?
Be sure you've selected "Custom Error Pages" in Error Page settings in IIS.
Login to IIS web server.
Expand the sites and select your website name.
From the Feature view, Under IIS section select the Error Pages.
Select the 404 error and right click on it.
Select the "Edit Feature Settings".
Select "Custom Error Pages" and click OK to save the settings.
I always use this approach. First, remove the error handling from system.web, then add this:
<system.webServer>
<httpErrors errorMode="DetailedLocalOnly" existingResponse="Replace">
<remove statusCode="404" />
<remove statusCode="500" />
<error statusCode="404" responseMode="ExecuteURL" path="/Errors/NotFound" />
<error statusCode="500" responseMode="ExecuteURL" path="/Errors/InternalError" />
</httpErrors>
</system.webServer>

Razor page as custom error message in asp.net without redirect

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?

iis custom error page not working

I create a error page in iis for 503 error. Now i stop my website application pool. i got the other page service unavailable not my custom error page. I also try to config in web.config. It's not working please help me..
tried 1
<httpErrors errorMode="Custom">
<remove statusCode="503" subStatusCode="-1" />
<error statusCode="503" prefixLanguageFilePath="" path="/503.htm"
responseMode="ExecuteURL" />
</httpErrors>
tried 2
<customErrors mode="On">
<error statusCode="503" redirect="~/503.htm"/>
</customErrors>
if the site is stopped this means no instance is listening to requests to this site. thus it is not possible to do so by web.config.
If what you mean is to use a custom page for site maintenance, you can take use of the app_offline.htm file:
Taking an ASP.NET Site Offline with a Message
http://weblogs.asp.net/pleloup/archive/2008/09/22/taking-an-asp-net-site-offline-with-a-message.aspx

How to config IIS to redirect to custom error page when accessing unsupported extension

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.

asp.NET - Custom Error Messages

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" />

Categories

Resources