custom 500 error page is classic asp - asp-classic

I'v got this in my web.config file.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<customErrors mode="On" redirectMode="ResponseRewrite">
<error statusCode="404" redirect="/404.asp" />
<error statusCode="500" redirect="/500.asp" />
</customErrors>
</system.web>
<system.webServer>
<httpErrors errorMode="Custom">
<remove statusCode="404" />
<error statusCode="404" path="/404.asp" responseMode="ExecuteURL" />
<remove statusCode="500" />
<error statusCode="500" path="/500.asp" responseMode="ExecuteURL" />
</httpErrors>
<defaultDocument>
<files>
<add value="home.asp" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
The 404 redirect works fine but the 500 redirect does nothing. I'm completely baffled. Little help. Thanks.

I use the following. Note the subStatusCode
<system.webServer>
<httpErrors>
<error statusCode="500" subStatusCode="100" path="/errorpage500-100.asp" responseMode="ExecuteURL"/>
</httpErrors>
</system.webServer>

Related

Skip CustomErrors and go to HttpErrors

I have web.config settings like this
<customErrors mode="On" >
<error statusCode="404" redirect="~/404" />
<error statusCode="403" redirect="~/500" />
<error statusCode="500" redirect="~/500" />
</customErrors>
and for httperrors
<httpErrors errorMode="Custom" >
<error statusCode="400" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\bad_request.html" />
<remove statusCode="401" subStatusCode="-1" />
<error statusCode="401" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\unauthorized.html" />
<remove statusCode="403" subStatusCode="-1" />
<error statusCode="403" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\forbidden.html" />
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\not_found.html" /><remove statusCode="405" subStatusCode="-1" />
<error statusCode="405" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\method_not_allowed.html" /><remove statusCode="406" subStatusCode="-1" />
<error statusCode="406" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\not_acceptable.html" />
<error statusCode="407" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\proxy_authentication_required.html" /><remove statusCode="412" subStatusCode="-1" />
<error statusCode="412" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\precondition_failed.html" />
<error statusCode="414" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\request-uri_too_long.html" /><error statusCode="415" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\unsupported_media_type.html" />
<remove statusCode="500" subStatusCode="-1" /><error statusCode="500" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\internal_server_error.html" />
<remove statusCode="501" subStatusCode="-1" /><error statusCode="501" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\not_implemented.html" />
<remove statusCode="502" subStatusCode="-1" /><error statusCode="502" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\bad_gateway.html" />
<error statusCode="503" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\maintenance.html" />
</httpErrors>
On 404 Error. Skipping 404 page and goes to .aspxerrorpath= page.aspx
and writing
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
I want to show my customized 404, 500 error page. What is the wrong
In short, in production it is possible to completely get rid of the "system.web -> customErrors" section, which is almost kept for the compatibility purposes (check the What is the difference between customErrors and httpErrors? thread to learn more), and where you also specify redirects. Then, specify the necessary redirects and custom error pages within the "system.webServer -> httpErrors" section only. Make sure that these HTML files exist on the web server and are available via the relative paths (or these pages exist inside one of a parent web app on the same web server, so that these "errors" settings are inherited).
Solution Explorer:
~/YourWebApp
...
not_found.html
Web.config
Web.config (for the 404 status code error):
<!--Dev: For Visual Studio Mode-->
<system.web>
<customErrors mode="On">
<error statusCode="404" redirect="~/not_found.html" />
</customErrors>
</system.web>
<!--Prod: For IIS Mode-->
<system.webServer>
<httpErrors errorMode="Custom">
<!--<error statusCode="404" path="C:\Inetpub\vhosts\domain.win2012.tld\error_docs\not_found.html" />-->
<error statusCode="404" path="~/not_found.html" responseMode="Redirect" />
</httpErrors>
</system.webServer>

Displaying custom error page on test case http://localhost/test. and htttp://localhost/test:

I need to redirect on error to error page on below test scenario,
http://localhost/admin800/test.
http://localhost/admin800/test:
Here is my code,
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime targetFramework="4.0" />
<customErrors mode="On" defaultRedirect="Error1">
<error statusCode="404" redirect="/admin600/error.aspx"/>
</customErrors>
</system.web>
<system.webServer>
<directoryBrowse enabled="false" />
<httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL" existingResponse="Replace">
<remove statusCode="500" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<remove statusCode="403" subStatusCode="-1" />
<error statusCode="404" path="/admin600/error.aspx" responseMode="ExecuteURL" />
<error statusCode="500" prefixLanguageFilePath="" path="/admin600/error.aspx" responseMode="ExecuteURL" />
<error statusCode="403" path="/admin600/error.aspx" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
Let me know what additional code i need to add in this web.configI have done project in web application project not in MVC.Looking forward to hear from you at the earliest.
Thanks in advance.
George
I am Using This Code In My Application:
<customErrors defaultRedirect="error.aspx" mode="On" />
Or This :
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>

How show different custom error pages for each area in ASP.NET MVC 5

I designed a website that have one area (manager) for administrators. In main web site i customized error pages easily in webconfig. with this:
<httpErrors errorMode="Custom" existingResponse="Replace" defaultResponseMode="ExecuteURL">
<remove statusCode="400"/>
<remove statusCode="401"/>
<remove statusCode="403"/>
<remove statusCode="404"/>
<remove statusCode="408"/>
<remove statusCode="409"/>
<remove statusCode="500"/>
<error statusCode="400" responseMode="ExecuteURL" path="/Error/400"/>
<error statusCode="401" responseMode="ExecuteURL" path="/Error/401"/>
<error statusCode="403" responseMode="ExecuteURL" path="/Error/403"/>
<error statusCode="404" responseMode="ExecuteURL" path="/Error/404"/>
<error statusCode="408" responseMode="ExecuteURL" path="/Error/408"/>
<error statusCode="409" responseMode="ExecuteURL" path="/Error/409"/>
<error statusCode="500" responseMode="ExecuteURL" path="/Error/500"/>
</httpErrors>
now i want to show administrators that are in manager area some different custom error pages (like their panels).
can someone tell me how can i do that?
EDIT:
I put a new web.config file in /Areas/Manager folder.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<httpErrors errorMode="Custom" existingResponse="Replace" defaultResponseMode="ExecuteURL">
<remove statusCode="400"/>
<remove statusCode="401"/>
<remove statusCode="403"/>
<remove statusCode="404"/>
<remove statusCode="408"/>
<remove statusCode="409"/>
<remove statusCode="500"/>
<error statusCode="400" responseMode="ExecuteURL" path="/Manager/Error/400"/>
<error statusCode="401" responseMode="ExecuteURL" path="/Manager/Error/401"/>
<error statusCode="403" responseMode="ExecuteURL" path="/Manager/Error/403"/>
<error statusCode="404" responseMode="ExecuteURL" path="/Manager/Error/404"/>
<error statusCode="408" responseMode="ExecuteURL" path="/Manager/Error/408"/>
<error statusCode="409" responseMode="ExecuteURL" path="/Manager/Error/409"/>
<error statusCode="500" responseMode="ExecuteURL" path="/Manager/Error/500"/>
</httpErrors>
</system.webServer>
</configuration>
i even put httpErrors part in ~/Areas/Manager/Views/web.config. but always for errors i see /Error/ErrorCode instead /Manager/Error/ErrorCode page.
Create a new web.config that goes in the Admin/Manager folder. That folder can then have it's own set of httpErrors that only apply to pages located in that folder.

404 Custom is blank with asp extension

My 404 Custom setup shows up as a blank page if it has an asp extension. If I change the extension of the custom error page to .html, the custom error page shows correctly.
this is my web.config file
<httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL" existingResponse="Auto">
<remove statusCode="404" subStatusCode="-1" />
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="500" subStatusCode="100" prefixLanguageFilePath="" path="/error_pages/error500.asp" responseMode="ExecuteURL" />
<error statusCode="404" subStatusCode="-1" prefixLanguageFilePath="" path="/error_pages/error404.asp" responseMode="ExecuteURL" />
</httpErrors>
I cant figure this out... driving me nuts
If you like to redirect when the error happens, use...
<httpErrors errorMode="Custom">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/time.asp" responseMode="Redirect" />
</httpErrors>
You may also hide the redirection, by using...
<httpErrors errorMode="Custom">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/time.asp" responseMode="ExecuteURL" />
</httpErrors>
You can also use Custom Errors (of ASP.NET) like so...
<system.web>
<customErrors mode="On">
<error redirect="time.asp" statusCode="404" />
</customErrors>
</system.web>

How to redirect all httpErrors to custom url?

These are the codes in web.config:
<system.web>
<customErrors mode="Off" >
</customErrors>
</system.web>
<system.webServer>
<httpErrors errorMode="Custom" existingResponse="Replace">
<clear />
<error statusCode="404" prefixLanguageFilePath="" path="/ResourceNotFound" responseMode="ExecuteURL" />
<error statusCode="500" prefixLanguageFilePath="" path="/ResourceNotFound" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
The above settings will redirect httpError of 404 and 500 only.
But instead of manually add all the error code of 400, 401, 403....etc..etc...
Can we just set it redirect all errors to the same url without typing all the error code?
<error statusCode="400" .....
<error statusCode="401" .....
<error statusCode="403" .....
<error statusCode="404" .....
<error statusCode="xxx" ....
The httpErrors section has defaultPath attribute.
<system.webServer>
<httpErrors defaultPath="Error.html" defaultResponseMode="File">
<clear />
</httpErrors>
</system.webServer>
http://www.iis.net/configreference/system.webserver/httperrors
However, I don't use it, because defaultPath is locked in IIS Express by default. Need to edit %homepath%\Documents\IISExpress\config\applicationHost.config to unlock it.
<httpErrors lockAttributes="allowAbsolutePathsWhenDelegated,defaultPath">
<!-- ... -->
</httpErrors>
try this,
add in web.config file.
<system.webServer>
<httpErrors errorMode="DetailedLocalOnly" defaultResponseMode="File" >
<remove statusCode="500" />
<error statusCode="500" prefixLanguageFilePath="C:\Contoso\Content\errors"
path="500.htm" />
</httpErrors>
</system.webServer>
and
<httpErrors existingResponse="Replace" defaultResponseMode="ExecuteURL" errorMode="Custom">
<remove statusCode="404" />
<error statusCode="404" path="/ErrorPages/Oops.aspx" responseMode="ExecuteURL"/>
<remove statusCode="401" />
<error statusCode="401" path="/Account/Login.aspx" responseMode="ExecuteURL"/>
<remove statusCode="501"/>
<error statusCode="501" path="/ErrorPages/Oops.aspx" responseMode="ExecuteURL"/>
<remove statusCode="411"/>
<error statusCode="411" path="/ErrorPages/Oops.aspx" responseMode="ExecuteURL"/>
<remove statusCode="403"/>
<error statusCode="403" path="/ErrorPages/Oops.aspx" responseMode="ExecuteURL"/>
</httpErrors>
and more about this http://www.iis.net/configreference/system.webserver/httperrors

Resources