MVC 2 customErrors works locally but not live? - asp.net-mvc

Here is what I have in my web.config:
<customErrors mode="On" defaultRedirect="/pages/sitemap">
<error statusCode="404" redirect="/pages/sitemap" />
</customErrors>
Locally this works just as expected but live for some reason I still get the vanilla 404 error page?
I am using MVC 2 with Areas, thoughts?

Just a quick thought, have you tried adding the ~ to your redirects? Your application/directory structure is probably different on PROD than on your local test machine.
<customErrors mode="On" defaultRedirect="~/pages/sitemap">
<error statusCode="404" redirect="~/pages/sitemap" />
</customErrors>
Also, take a look if you have the something similar to the following snippet in your web.config
<httpErrors errorMode="DetailedLocalOnly">
<error statusCode="403" subStatusCode="4" path="custerr\403.4.htm" responseMode="File" />
</httpErrors>
This 'could' be overriding your settings.

Related

Error returning html response instead of error page

I've setup a custom error.html page and when a user tries to upload a large file it throws an error due to max request length (expected behaviour).
However, instead of returning a rendered page it returns the html of the error page and the network shows a 200 response instead of 500.
Here is what I have in the web config
<system.web>
<customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/error.html">
<error statusCode="404" redirect="~/error.html" />
<error statusCode="500" redirect="~/error.html" />
</customErrors>
</system.web>
and under the webServer section
<system.webServer>
<httpErrors errorMode="Custom">
<remove statusCode="404" />
<error statusCode="404" path="error.html" responseMode="File" />
<remove statusCode="500" />
<error statusCode="500" path="error.html" responseMode="File" />
</httpErrors>
</system.webServer>
It could be that these sections maybe conflicting with each other.
The expected error page is displayed for a 404.
(Increasing the limit is possible but won't stop the issue happening from a different error)

Remove all IIS error messages via <httpErrors> in web.config

I'm implementing the following:
<httpErrors errorMode="Custom">
<remove statusCode="404" />
<error statusCode="404" path="~/Error" responseMode="ExecuteURL" prefixLanguageFilePath="" />
<remove statusCode="500" />
<error statusCode="500" path="~/Error" responseMode="ExecuteURL" prefixLanguageFilePath="" />
</httpErrors>
However I'd like to remove ALL IIS error pages so that none of my internal details are exposed on 404, 403, 500 etc. I've tried to use:
<remove statusCode="*" />
To no avail. Is there a standard solution here?
As #Peter said, you can use the <clear> element.
You can use the <remove> element to remove a specific error message from the collection of error messages your site or application inherits from a higher level in the IIS configuration hierarchy. Also, you can use the <clear> element to remove all HTTP error messages from the collection of HTTP error messages that your site or application inherits.
Reference: iis.net
Example:
<httpErrors errorMode="Custom">
<clear />
<error statusCode="404" path="/Error" responseMode="ExecuteURL" />
<error statusCode="500" path="/Error" responseMode="ExecuteURL" />
</httpErrors>
(Side note: Virtual paths are not allowed in the path attribute of the error element.)

Elmah not logging 404 errors after third folder, and 403 errors at all

Continuing my previous question, I handle custom errors in my mvc5 app using:
<system.webServer>
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404"/>
<error statusCode="404" path="/Errors/NotFound" responseMode="ExecuteURL" />
<remove statusCode="403"/>
<error statusCode="403" path="/Errors/NotFound" responseMode="ExecuteURL" />
<remove statusCode="500"/>
<error statusCode="500" path="/Errors/ServerError" responseMode="ExecuteURL" />
</httpErrors>
...
</system.webServer>
This enabled me to show custom 404 error page after the 3rd folder (e.g. site.com/a/b/c/nothing-here). Yet, Elmah is not logging these errors. This is also true for 403 errors. So My questions are:
is there a way to make Elmah handle all server errors regardless of
being thrown by the mvc app itself?
if not, since /Errors/NotFound is successfully executed, I can add a log from that action. is there a way to tell if Elmah already handled this error (or was it thrown by the mvc app)?

Asp.Net MVC catch 404 for unknown extensions

I'm able to catch almost every 404 but this:
http://example.com/mariajosefa.pedro de heredia
The file "mariajosefa.pedro de heredia" doesn't exists.
This seems to be catched by IIS and my users are presented with the standard IIS 404 error page.
Is this possible?
Sorry for the quick answer :( for reference, this is what works for me:
In web.config:
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="/Home/NotFound" responseMode="ExecuteURL"/>
</httpErrors>
ALSO REMOVE THE COLON FROM THE INVALID CHARACTERS LIST, THIS WAS ALSO BOTHERING ME
<httpRuntime targetFramework="4.5.1" requestPathInvalidCharacters="<,>,*,%,&,\,?"/>

How to set Error page in webconfig for mvc web based system

I have MVC 4 web based system. I need to handle error page in web.config file. I m try do with httpError syntax. When 404 it will show blank page. not show the actual error page. url also not show as error page.
web.config code:
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" />
<error statusCode="404" responseMode="ExecuteURL" path="~/Error/PageNotFound.htm" />
</httpErrors>
please help this.
Try looking at this page: Error Handling and Nice Error pages.
It says to add the following in the Web.Config:
<customErrors mode="On" defaultRedirect="~/Content/Errors/page500.aspx" redirectMode="ResponseRewrite">
<error statusCode="404" redirect="~/Content/Errors/page404.aspx" />
</customErrors>
I haven't got my MVC code infront of me but I think this is what I did.

Resources