I've got custom error mode "On" in my web.config. However, the ASPX error page still shows for certain kinds of particular URL
Not OK
https://example.com/*~1*%5ca.aspx <-- Return 404 - File or directory not found.
OK
https://example.com/abc.aspx <-- can redirect to custom page
I'm using Windows Server 2012 Azure. I disabled the NtfsDisable8dot3NameCreation in the registry, but still no luck. What can be the root cause?
My web config
<customErrors mode="On" defaultRedirect="~/error/Error403.html">
<error statusCode="400" redirect="~/error/Error400.html" />
<error statusCode="401" redirect="~/error/Error400.html" />
<error statusCode="402" redirect="~/error/Error400.html" />
<error statusCode="403" redirect="~/error/Error403.html" />
<error statusCode="404" redirect="~/error/Error404.html" />
<error statusCode="500" redirect="~/error/Error500.html" />
<error statusCode="501" redirect="~/error/Error501.html" />
<error statusCode="502" redirect="~/error/Error502.html" />
<error statusCode="503" redirect="~/error/Error503.html" />
<error statusCode="504" redirect="~/error/Error504.html" />
</customErrors>
<httpErrors errorMode="Custom" existingResponse="Auto" defaultResponseMode="ExecuteURL">
<remove statusCode="400" subStatusCode="-1"/>
<remove statusCode="401" subStatusCode="-1"/>
<remove statusCode="402" subStatusCode="-1"/>
<remove statusCode="403" subStatusCode="-1"/>
<remove statusCode="404" subStatusCode="-1"/>
<remove statusCode="500" subStatusCode="-1"/>
<remove statusCode="501" subStatusCode="-1"/>
<remove statusCode="502" subStatusCode="-1"/>
<remove statusCode="503" subStatusCode="-1"/>
<remove statusCode="504" subStatusCode="-1"/>
<!--<error statusCode="500" path="error\InternalServerError.htm"/>
<error statusCode="404" path="error\PageNotFound.htm"/>-->
<error statusCode="400" prefixLanguageFilePath="" responseMode="ExecuteURL" path="/error/Error400.html" />
<error statusCode="401" prefixLanguageFilePath="" responseMode="ExecuteURL" path="/error/Error400.html" />
<error statusCode="402" prefixLanguageFilePath="" responseMode="ExecuteURL" path="/error/Error400.html" />
<error statusCode="403" prefixLanguageFilePath="" responseMode="ExecuteURL" path="/error/Error400.html" />
<error statusCode="404" prefixLanguageFilePath="" responseMode="ExecuteURL" path="/error/Error404.html" />
<error statusCode="500" prefixLanguageFilePath="" responseMode="ExecuteURL" path="/error/Error500.html" />
<error statusCode="501" prefixLanguageFilePath="" responseMode="ExecuteURL" path="/error/Error501.html" />
<error statusCode="502" prefixLanguageFilePath="" responseMode="ExecuteURL" path="/error/Error502.html" />
<error statusCode="503" prefixLanguageFilePath="" responseMode="ExecuteURL" path="/error/Error503.html" />
<error statusCode="504" prefixLanguageFilePath="" responseMode="ExecuteURL" path="/error/Error504.html" />
</httpErrors>
I think you should get 400 error more than 404 error because "*" is not a valid request.path for .NET runtime and the exception was thrown from CLR. That's why IIS custom error page would never work.
Please try to set requestPathInvalidCharacters to null or manual specify invalid characters for your runtime.
<system.web>
<compilation targetFramework="4.8" />
<httpRuntime requestPathInvalidCharacters=""/>
<customErrors mode="RemoteOnly">
<error redirect="https://www.jokiesd.com/404.aspx" statusCode="404" />
</customErrors>
</system.web>
Edit:
I can' reproduce this issue on my 2012 server. Have you tried to replace the URL to abosolute URL?
Related
I have a Umbraco site and have configured the custom error pages for 404 (page not found) and 500 (internal server errors). When I try to access a page which is not existing, I get the custom 404 page. But the HTTP status code returned is 200 rather than 404. Can someone suggest a solution, I am looking for HTTP Status code 404 to be returned.
I have the following mentioned in the Config file
<customErrors defaultRedirect="errorPages/500.html" mode="RemoteOnly">
<error statusCode="404" redirect="errorPages/404.html" />
<error statusCode="403" redirect="errorPages/403.html" />
<error statusCode="500" redirect="errorPages/500.html" />
<error statusCode="404" redirect="errorPages/503.html" />
</customErrors>
<httpErrors existingResponse="Replace" errorMode="Custom">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/errors/404" responseMode="ExecuteURL" />
<remove statusCode="403" subStatusCode="-1" />
<error statusCode="403" prefixLanguageFilePath="" path="/errors/403" responseMode="ExecuteURL" />
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="500" prefixLanguageFilePath="" path="/errors/500" responseMode="ExecuteURL" />
</httpErrors>
Thanks
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>
I have added following in my webconfig. It works when site is hosted to IIS but not when I run locally. It gives me error of wrong web.config.
<system.webServer>
<httpErrors errorMode="Custom" defaultPath="ShowError.aspx" defaultResponseMode="ExecuteURL">
<remove statusCode="404" subStatusCode="-1" />
<remove statusCode="403" subStatusCode="-1" />
<remove statusCode="401" subStatusCode="-1" />
<remove statusCode="405" subStatusCode="-1" />
<remove statusCode="406" subStatusCode="-1" />
<remove statusCode="412" subStatusCode="-1" />
<remove statusCode="500" subStatusCode="-1" />
<remove statusCode="501" subStatusCode="-1" />
<remove statusCode="502" subStatusCode="-1" />
</httpErrors>
</system.webServer>
The defaultPath attribute is locked by default, which causes the 500.19 error. You can either:
Unlock defaultPath by removing it from your applicationHost.config, which I do not recommend because then you'll have to configure this on every developer and production server.
Remove defaultPath and defaultResponseMode from <httpErrors> and specify path and responseMode on each <error>, like so:
<httpErrors errorMode="Custom">
<clear />
<error statusCode="404" responseMode="ExecuteURL" path="ShowError.aspx" />
<error statusCode="403" responseMode="ExecuteURL" path="ShowError.aspx" />
<error statusCode="401" responseMode="ExecuteURL" path="ShowError.aspx" />
<error statusCode="405" responseMode="ExecuteURL" path="ShowError.aspx" />
<error statusCode="406" responseMode="ExecuteURL" path="ShowError.aspx" />
<error statusCode="412" responseMode="ExecuteURL" path="ShowError.aspx" />
<error statusCode="500" responseMode="ExecuteURL" path="ShowError.aspx" />
<error statusCode="501" responseMode="ExecuteURL" path="ShowError.aspx" />
<error statusCode="502" responseMode="ExecuteURL" path="ShowError.aspx" />
</httpErrors>
It might seem excessive to specify each status code separately, but there is no other way when using httpErrors. I would recommend you to add 400 (Bad Request).
Some side notes:
You can omit subStatusCode="-1" because -1 is the default value of subStatusCode.
If you're going to remove/replace all default IIS error pages, you might as well use <clear />.
You might want to remove errorMode="Custom" when you've got your error pages working, because this will hide error details from developers, slowing down productivity while debugging. A good error page is only returned for remote requests, which is what the default value (errorMode="DetailedLocalOnly") will do.
If you can't get the error pages to work, try responseMode="Replace". You also want to avoid using this in developer environments for the same reasons as the above.
If you have custom error pages, try this:
<system.webServer>
<httpErrors errorMode="DetailedLocalOnly" existingResponse="Auto">
<remove statusCode="403" />
<remove statusCode="404" />
<remove statusCode="500" />
<error statusCode="403" responseMode="ExecuteURL" path="/Error/AccessDenied" />
<error statusCode="404" responseMode="ExecuteURL" path="/Error/NotFound" />
<error statusCode="500" responseMode="ExecuteURL" path="/Error/InternalServerError" />
</httpErrors>
If you want custom error pages on local, you can change DetailedLocalOnly to Custom.
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>
I am facing a starnge issue with one of my server, I've setup the custom error pages however error pages are not showing up when I have file extension in URL for example it does not work for somedomain.com/abcd.aspx or somedomain.com/abcd.aspx, it just show me blank page.
It is working if I dont have file extension in my URL for example http://somedomain.com/abcd works fine.
Following is the configuration setting in web.config file
<httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL" existingResponse="Replace">
<remove statusCode="502" subStatusCode="-1" />
<remove statusCode="501" subStatusCode="-1" />
<remove statusCode="500" subStatusCode="-1" />
<remove statusCode="412" subStatusCode="-1" />
<remove statusCode="406" subStatusCode="-1" />
<remove statusCode="405" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<remove statusCode="403" subStatusCode="-1" />
<remove statusCode="401" subStatusCode="-1" />
<error statusCode="401" prefixLanguageFilePath="" path="/Error/Error400.aspx" responseMode="ExecuteURL" />
<error statusCode="403" prefixLanguageFilePath="" path="/Error/Error400.aspx" responseMode="ExecuteURL" />
<error statusCode="404" prefixLanguageFilePath="" path="/Error/Error400.aspx" responseMode="ExecuteURL" />
<error statusCode="405" prefixLanguageFilePath="" path="/Error/Error400.aspx" responseMode="ExecuteURL" />
<error statusCode="406" prefixLanguageFilePath="" path="/Error/Error400.aspx" responseMode="ExecuteURL" />
<error statusCode="412" prefixLanguageFilePath="" path="/Error/Error400.aspx" responseMode="ExecuteURL" />
<error statusCode="500" prefixLanguageFilePath="" path="/Error/Error500.aspx" responseMode="ExecuteURL" />
<error statusCode="501" prefixLanguageFilePath="" path="/Error/Error500.aspx" responseMode="ExecuteURL" />
<error statusCode="502" prefixLanguageFilePath="" path="/Error/Error500.aspx" responseMode="ExecuteURL" />
</httpErrors>
Any help or pointers will be great.
Regards,
Sameer
I'm sure you've already solved this by now, but for others searching for the answer, I ran into this same issue today and was able to solve it by adding a customError handler in addition to the httpErrors.
Change:
<system.web>
<customErrors mode="Off" />
to:
<system.web>
<customErrors mode="RemoteOnly">
<error redirect="/Errors/404" statusCode="404" />
</customErrors>