IIS6 - Why won't my Custom error page display? - asp.net

I have a custom error page that should display for HTTP 404 errors. It does not and I am having difficulty figuring out why.
My web.config is set
<customErrors mode="On" />
Fiddler shows a 401.2, followed by a 404 for a single POST. Both errors should be custom. The 401.2 is working because I see it in fiddler. The 404 happens immediately after so all I see in the browser is the generic 404 error. I should see my custom 404 page.
Why won't my custom HTTP 404 page showup?

What's the URL you are testing with? If it's not a file type handled by ASP.NET (e.g. /foo/bar.txt) then you won't see the ASP.NET defined 404 handler.
-Oisin

If you're looking for what the 404.x codes mean here's this
HTTP 404.x-File or Directory Not Found
None - File or directory not found.
1 - Web site not accessible on the requested port.
2 - Web service extension lockdown policy prevents this request.
3 - MIME map policy prevents this request.
Seems to be an IIS specific code, not sure if IIS sends these details with the response

Related

Custom Page 404 isn't shown on server (asp .net framework 4.8)

On our websites as someone visits a non-existing page, we dinamically create a 404 error page that returns a status code 404.
It works perfectly on localhost, but on the server the same page returns the standard 404 IIS (7.0) error
(IISError) instead of the custom one CustomError.
We can't edit the web.config file because we don't have a physical page to redirect to.
Is it possible that there is a IIS configuration that prevents our custom error page from showing?
There is a configuration setting in IIS. Click your application in IIS, and find Error pages settings.
For the error code, you could specify location of your custom page.

Not displaying 404 aspx page from site or server

How can I force IIS and ASP.NET WebForms to go to our custom error page for an undefined routing?
I've reviewed the question asp-net-not-displaying-a-custom-404-page-as-configured.
We are using IIS 7.5
ASP.NET 4.0
Web Forms
If we have a request for http://www.oursite.com/searches, and we don't have "searches" defined in our routing map. We're getting a blank page back from the request with a 404 Status. We have:
Default 404 page at the server level
Default 404 page at the website level
Default error page defined in the web.config file
In our code, if throw an HTTPException of 404 we end up on our custom 404 page. If we request an ASPX page that doesn't exist we get our custom error page. If I add a default "catchall" routing for our site at the end of the routes, our cart process stops working.
When you search like - http://www.oursite.com/searches and it returns a blank page back from the request with a 404 Status. Its an http protocol error returning from IIS/Web Server. Your web config settings for custom error page will work only for .net framework exception. Configure your IIS to go to your custom error page that returns a 404 error.

How do I get a friendly error page to replace the asp.net error page for url "WEB-INF./web.xml"?

This url is part of a pci compliance scan and it is flagging the very sparse asp.net error page returned, which on the live site is a 500 status code and the text
Server Error in '/' Application.
Runtime Error
Description: An exception occurred while processing your request.
Additionally, another exception occurred while executing the custom
error page for the first exception. The request has been terminated.
When running the site in visual studio I however get a 404 and the text
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its
dependencies) could have been removed, had its name changed, or is
temporarily unavailable. Please review the following URL and make
sure that it is spelled correctly.
Requested URL: /WEB-INF./web.xml
Version Information: Microsoft .NET Framework Version:4.0.30319;
ASP.NET Version:4.0.30319.18044
I've tried ignoring that url in routing and mapping it to our 404 route /error/not-found, we have custom errors on with a default redirect to /error/internal. I also tried using a location tag to deny access, blocking it with request filtering, and using a handler with that path to catch the request.
I tried this rewrite, also tried the same rule blocking and redirecting but I still get the same asp.net error page. The image cut off but the rule is ^.*\./.*$ and it does match the url I am trying to filter (I've also tried simply WEB-INF).
Any idea how I can get this url to show our custom error page?
Adding relaxedUrlToFileSystemMapping="true" to the httpRuntime node in the web.config allowed this url to get processed by ASP.Net MVC as expected.
<system.web>
<httpRuntime relaxedUrlToFileSystemMapping="true" />
</system.web>
You could use Managed Fusion's rewriter library located here, it works similarly to redirecting through Apache configuration: http://managedfusion.com/products/url-rewriter/
The documentation for how to use it is here: http://managedfusion.com/products/url-rewriter/documentation.aspx

Custom http error pages for images?

I know it's common for pages to redirect to a custom error page for 404 errors and such. But say somebody opens the url in their browser for an image that doesn't exist for example http://mysite.com/nothinghere.gif. This site returns a 404 error but it's not just the browser default, it's a custom 404. How do you configure an ASP.NET site on IIS7 to do this? the customerrors section in the web.config doesn't seem to apply to things like images, css, js, etc
customErrors section would apply to resources managed by ASP.NET. IIS7 has its own httpErrors section under webserver node. Of course, there is also UI to configure it. Anyway error handling behavior also changes based on you are running your ASP.NET application under classic mode or integrated mode. I will suggest that you read following articles to get hold of it.
http://www.braintrove.com/article/46 - this will tell you how to set up IIS7's own cutom error pages
Below explains IIS7 errors handling
http://learn.iis.net/page.aspx/267/how-to-use-http-detailed-errors-in-iis-70/
http://blogs.iis.net/ksingla/archive/2008/02/18/what-to-expect-from-iis7-custom-error-module.aspx
Make your custom error page a script.
When its called you can either send a html response for a page missing or query the request to find out the image name and then send an image or redirect to an image.
try these links for issues with custom 404 errors
IIS 404 Custom Error not working as expected
http://forums.asp.net/p/1603843/4089618.aspx

Why does the ASP.NET error page return 404 as soon as the aspxerrorpath querystring is present?

I have configured an ASP.NET application as follows:
<customErrors mode="RemoteOnly" defaultRedirect="~/Error.aspx"/>
When I browse to the ~/Error.aspx file the server returns 200 and the page is rendered. But if the user is redirected to the error page a querystring is appended to the path:
/Error.aspx?aspxerrorpath=/Test.aspx
But whenever this querystring is used the server doesn't render the error page, instead it returns a 404 using the server's custom error page, not Error.aspx
Why doesn't the web.config setting result in ~/Error.aspx being rendered?
I believe I've tracked down the problem. Due to a recent ASP.NET security vulnerability (see Scott Guthrie's post), one of the recommended actions was to put in a URLScan rule that prohibits any urls with a querystring with "aspxerrorpath=" in it. So your url is cut off before it even gets to ASP.NET and a default 404 is returned.
To check if this is your problem, you can "aspxerrorpath=xx" to ANY page url on your site, and it should return a 404 error.
Now that a patch has been released to fix this vulnerability in asp.net, you should be able to get rid of that rule and then your error page redirects should work again.

Resources