web.config custom httpErrors not redirecting... "The page cannot be displayed because an internal server error has occurred." instead - iis-7

I'm trying to get custom error pages work to no avail. This configuration is adapted from samples I've found online. Using IIS 7.0 hosted by GoDaddy.
The below code gives me "The page cannot be displayed because an internal server error has occurred." instead of redirecting.
<configuration>
<system.webServer>
<httpErrors>
<remove statusCode="401" subStatusCode="-1" />
<remove statusCode="403" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="401" path="http://www.mywebsite.com/error.html" responseMode="Redirect" />
<error statusCode="403" path="http://www.mywebsite.com/error.html" responseMode="Redirect" />
<error statusCode="404" path="http://www.mywebsite.com/error.html" responseMode="Redirect" />
<error statusCode="500" path="http://www.mywebsite.com/error.html" responseMode="Redirect" />
</httpErrors>
</system.webServer>
<system.web>
<customErrors mode="On"/>
</system.web>
</configuration>

This issue can sometimes happen on a shared hosting plan. See, https://forums.asp.net/t/1894946.aspx?Not+getting+custom+error+page, last post:
"You cannot modify the HTTP Error pages on Windows shared hosting plans outside of the 404 error page, which is why you are experiencing the issues"
So, if you have something like this:
<httpErrors errorMode="Custom" existingResponse="Replace">
<clear />
<error statusCode="400" responseMode="Redirect" path="/Errors/404error.html" />
<error statusCode="403" responseMode="Redirect" path="/Errors/404error.html" />
<error statusCode="404" responseMode="Redirect" path="/Errors/404error.html" />
<error statusCode="500" responseMode="Redirect" path="/Errors/404error.html" />
</httpErrors>
You'll get the error "The page cannot be displayed because an internal server error has occurred." but if you change it to this:
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" />
<error statusCode="404" responseMode="Redirect" path="\Errors\404error.html"/>
</httpErrors>
It will work.
A full discussion of why this happens on GoDaddy can be found on this old forum thread here: https://web.archive.org/web/20130131011933/https://support.godaddy.com/groups/web-hosting/forum/topic/custom-http-error-pages-on-4gh-windows-shared-hosting/ .
There lots of other issues why your custom errors may not be working, but this particular one doesn't seem to be well documented, so I thought I'd post it here for others.

Related

HttpErrors PassThrough specific statuscode

I Added this section to web.config, to show custom error for 500, and 404 errors.
<httpErrors errorMode="Custom" existingResponse="Replace">
<clear/>
<error statusCode="500" responseMode="ExecuteURL" path="/CustomError/ServerError" />
<error statusCode="404" responseMode="ExecuteURL" path="/CustomError/NotFound" />
</httpErrors>
I want to set the status code manually for some pages to 423 'Business requirements', my question how can I pass through specific statuscode?
Thanks in advance.

Custom error redirect on 404 code for non-aspx files

I added to my web.config:
<customErrors mode="RemoteOnly" defaultRedirect="~/Pages/Error/Error.aspx">
<error statusCode="404" redirect="~/Pages/Error/Error404.aspx"/>
</customErrors>
and it works fine for .aspx pages.
When I try to type: http://domainname.com/notExist, I get the default 404.
I tried the suggestions from:
404 Redirecting for non aspx pages
but nothing works for me.
Any ideas why?
I use .net 3.5, application pool pipeline mode is Integrated.
After adding <httpErrors> I get:
Try This, it will provide separate status. Then you can execute as per your requirement.
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="~/Pages/Error/Error.aspx">
<error statusCode="404" redirect="~/Pages/Error/Error404.aspx"/>
</customErrors>
</system.web>
<system.webserver>
<asp scriptErrorSentToBrowser="true"/>
<httpErrors errorMode="Detailed">
<error statusCode="401" path="/Pages/Error/Error.aspx" responseMode="Redirect" />
<error statusCode="403" path="/Pages/Error/Error.aspx" responseMode="ExecuteURL" />
<error statusCode="404" path="/Pages/Error/Error404.aspx" responseMode="ExecuteURL" />
<error statusCode="500" path="/Pages/Error/Error.aspx" responseMode="ExecuteURL" />
</httpErrors>
</system.webserver>
You need to separate setting for other pages.
Try something like this.
<system.webserver>
<httpErrors errorMode="Custom" >
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="~/Pages/Error/Error404.aspx" />
</httpErrors>
</system.webserver>

Custom 404 Page NOT Served for extensionless URL

I am running into a situation,
My custom 404 page works just fine with URL that has extensions.
http://www.space.ca/ssss.aspx
A custom page URL serves up as intended,
however, if you try the link without the .aspx extension
http://www.space.ca/ssss
it goes to the IIS default page. Any idea on why?
This is my configuration , inside system.webserver
<httpErrors>
<remove statusCode="500" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/errors/404.aspx" responseMode="ExecuteURL" />
<error statusCode="500" prefixLanguageFilePath="" path="/errors/500.aspx" responseMode="ExecuteURL" />
</httpErrors>
I know that this was posted quite a while ago, however this may help others...
I had the same issue and it was mainly down to having '~' within the path values, sadly this is not what your problem but if you follow the following then you should be okay...
<customErrors mode="On" redirectMode="ResponseRewrite">
<error statusCode="401" redirect="~/Errors/Unauthorized.aspx" />
<error statusCode="403" redirect="~/Errors/Forbidden.aspx" />
<error statusCode="404" redirect="~/Errors/PageNotFound.aspx" />
<error statusCode="500" redirect="~/Errors/ServerError.aspx" />
<error statusCode="501" redirect="~/Errors/ServerError.aspx" />
</customErrors>
<httpErrors errorMode="Custom">
<remove statusCode="401" subStatusCode="-1" />
<remove statusCode="403" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<remove statusCode="500" subStatusCode="-1" />
<remove statusCode="501" subStatusCode="-1" />
<error statusCode="401" path="/Errors/Unauthorized.aspx" responseMode="ExecuteURL" />
<error statusCode="403" path="/Errors/Forbidden.aspx" responseMode="ExecuteURL" />
<error statusCode="404" path="/Errors/PageNotFound.aspx" responseMode="ExecuteURL" />
<error statusCode="500" path="/Errors/ServerError.aspx" responseMode="ExecuteURL" />
<error statusCode="501" path="/Errors/ServerError.aspx" responseMode="ExecuteURL" />
</httpErrors>
Of course you only need to added entries for those status codes you wish to create a custom page for. Also remember that httpErrors should be placed in the section, and the customErrors within the section.
You could add the customErrors section in as this handles managed code. httpErrors section will handle errors for all content.
Please also note one final thing...When you are testing on the local machine the default for both ASP.NET and HTTP errors is to show detailed information on the local browser. You will need to set customErrors mode="On" AND httpErrors errorMode="Custom" in order to see the custom errors on the local machine.
More information can be found here: http://www.iis.net/ConfigReference/system.webServer/httpErrors
This works for me.
<httpErrors errorMode="Custom" existingResponse="Replace" defaultResponseMode="ExecuteURL">
<clear />
<error statusCode="404" path="~/error404.aspx" responseMode="Redirect" />
</httpErrors>

Example of Configuration for <httpErrors>

I have a Web Application in Asp.Net 4 running locally on IIS 7.
I need display a Custom Page (404) and an 500 instead for the defaults page for IIS.
Using this httpErrors in Web.Config
<system.webServer>
<httpErrors>
My Site is in
C:\inetpub\wwwroot\mysite\
My Custom Error page in:
C:\inetpub\wwwroot\mysite\ErrorPages\404.htm
C:\inetpub\wwwroot\mysite\ErrorPages\505.htm
I do not understand how it works. COuld you please provide me a sample of code?
Thanks
I solved my problem with this.
<httpErrors errorMode="Custom">
<remove statusCode="404" subStatusCode='-1' />
<remove statusCode="500" subStatusCode='-1' />
<error statusCode="404" path="/404.aspx" prefixLanguageFilePath="" responseMode="ExecuteURL" />
<error statusCode="500" path="/500.aspx" prefixLanguageFilePath="" responseMode="ExecuteURL" />
</httpErrors>
This needs to go in Web.config, under <configuration> > <system.webServer>
e.g.
<configuration>
<system.webServer>
<httpErrors ...>
// define errors in here ...
</httpErrors>
</system.webServer>
</configuration>
Here is an example, hope it helps
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="default.aspx">
<error statusCode="404" redirect="~/ErrorPages/404.htm"/>
<error statusCode="500" redirect="~/ErrorPages/505.htm"/>
</customErrors>
</system.web>
Edit for comments: Here's the example I think you need
<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>
http://www.iis.net/ConfigReference/system.webServer/httpErrors/error

Asp.net - Web.Config - Custom Errors

How can I set 404 and other error pages using web.config? I have tried adding following block in web.config.
<customErrors defaultRedirect="Forms/Errors/Page_404.aspx" mode="On">
<error statusCode="500" redirect="servererror.aspx" />
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="Forms/Errors/Page_404.aspx" />
</customErrors>
but still its showing default error page of IIS7. How to fix this?
I solved it myself. We need to add another section in web.config like below to make it work in IIS 7 / 7.5. For IIS 6 the one works which I mentioned in my question
<system.webServer>
...
<httpErrors errorMode="Custom" >
<remove statusCode="403" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="404" path="/404.aspx" responseMode="Redirect" />
<error statusCode="403" path="/403.aspx" responseMode="Redirect" />
<error statusCode="500" path="/500.aspx" responseMode="Redirect" />
</httpErrors>
...
</system.webServer>
Thanks to everyone who answered.
Try putting this in the system.webServer section of your Web.config
<system.webServer>
<httpErrors existingResponse="PassThrough" />
</system.webServer>
Try to add the "~/" before paths:
<customErrors defaultRedirect="~/Forms/Errors/Page_404.aspx" mode="On">
<error statusCode="500" redirect="~/servererror.aspx" />
<error statusCode="403" redirect="~/NoAccess.htm" />
<error statusCode="404" redirect="~/Forms/Errors/Page_404.aspx" />
</customErrors>
It looks like you're using a relative path there. Could that be the problem?
Try using Fiddler to see what page your browser is being redirected to.

Resources