Custom error page is not displaying on IIS7 ASP.NET - c#

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>

Related

IIS display standard yellow page instead of custom error page defined

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>

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.

iis 7 error when trying to add defaultPath to httpError in web config

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.

How to redirect all errors, including 404

I'd like all errors to go to the same error page. I did initially try the error tag with statuscodes. That works fine but I'd rather not have to specify so any statuscodes and still have every error go to one page. The problem is that if I remove the statuscode entries, a 404 goes to the server's 404 page and not my error page.
Is there some way to configure all errors to go to the same page?
You should change your web.config and add the customErrors element. You can then set the default redirect to a signle page
For Example
<customErrors mode="On" defaultRedirect="Error.aspx">
</customErrors>
You can refer to the MSDN article
http://msdn.microsoft.com/en-us/library/h0hfz6fc.aspx
On IIS7, you can use the new httpErrors section
<system.webServer>
<httpErrors defaultPath="Error.aspx" defaultResponseMode="Redirect">
</httpErrors>
</system.webServer>
For more information
http://www.iis.net/ConfigReference/system.webServer/httpErrors
If I understand well, you need to send all errors to your custom error page, and the errors that iis7 gives (not only your program)
This is something that you need to setup on II7, but you can also setup it from web.config (but actually give instructions to ii7) Here is an example
<configuration>
<system.webServer>
<httpErrors errorMode="DetailedLocalOnly" defaultResponseMode="File" >
<remove statusCode="500" />
<error statusCode="500"
prefixLanguageFilePath="C:\Contoso\Content\errors"
path="500.htm" />
</httpErrors>
</system.webServer>
</configuration>
reference: http://www.iis.net/ConfigReference/system.webServer/httpErrors

Categories

Resources