IIS7 append "aspxerrorpath" querystring for 404 - iis-7

How do I append "aspxerrorpath" querystring to custom error page on 404 in IIS7
My web.config
<httpErrors errorMode="Custom" >
<remove statusCode="404" subStatusCode="-1"/>
<error statusCode="404" responseMode="Redirect" path="http://<domain>/error.aspx" />
</httpErrors>

Related

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

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.

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>

Asp.net web.config Handle Error page "File or directory not found"

I have page i.e. Default.aspx. I can handle error pages like 404,403. But when I change the extention of page then server give me an error.If I change Default.aspx to Default.asasd. Here I have just changed the extention of page then server gives following error
I added 404 error page in my web.config file. How can I solve this?
Web.config
<customErrors mode="On" defaultRedirect="~/ErrorPages/DefaultErrorPage.aspx" redirectMode="ResponseRedirect">
<error statusCode="404" redirect="~/ErrorPages/404.aspx" />
<error statusCode="403" redirect="~/ErrorPages/403.aspx" />
</customErrors>
Add this:
<system.webServer>
<httpErrors errorMode="Custom">
<remove statusCode="404" />
<error statusCode="404" path="/Error.aspx" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>

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