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.
Related
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.
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>
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>
i have successfully added a custom 404 page. what I want to do is to create another custom error page that is displayed when there is any error other than 404. e.g. 500, 403 etc.
this is what I have right now in webconfig
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="/404.aspx" responseMode="ExecuteURL"/>
</httpErrors>
Oh, my. I cannot believe I could not find a proper answer for this simple question! Nevertheless, after 2 hours of reading the docs and debugging, I found it.
<httpErrors errorMode="Custom" existingResponse="Auto" defaultResponseMode="ExecuteURL" defaultPath="/App/Error"> <!-- Do not include ~, this was my issue all long -->
<clear/> <!-- so that IIS provided error pages are skipped -->
<!-- add those which you like to provide a view of yours -->
<error path="/App/Http404" responseMode="ExecuteURL" statusCode="404"/>
<error path="/App/Http503" responseMode="ExecuteURL" statusCode="503"/>
</httpErrors>
Beaware that <httpErrors> configures IIS, while <customErrors> configures ASP.NET and some older versions of IIS (<=6?).
You can use customErrors in webconfig :
<customErrors mode="On" defaultRedirect="~/DefaultError.aspx?msg=SomeMessage">
<error statusCode="404" redirect="~/PageNotFound.html"/>
<error statusCode="403" redirect="~/AccessDenied.html"/>
</customErrors>
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.