I have developed an MVC5 page and have this in web.config:
<customErrors mode="On" defaultRedirect="/Home/Error" />
the problem is that this only works when I enter a non existing file in URL, for example, "/images/nonexisting". However, when I enter just "/images/" in URL (this folder does exist), an
"Error HTTP 403.14 - Forbidden"
is shown instead of custom error page.
How can I solve this?
EDIT: this is not duplicated. Referenced page is about defaultRedirect not taking into account at all. In my case, it works but only for 404 errors. For 403.14 errors, it does not work.
One other fact took my attention.
When I placed mode=Off in customErrors tag, and tried to load "/images/nonexisting", I get this error:
However, when I tried to load /images/, I got the following page:
As you see, both pages have different look. I think that is why it does not work, but I am not sure how to solve it.
It seems 404 errors are trapped by .NET Framework but 403 errors are trapped by the Web server not actually reaching the web site (that may be why custom error page is not shown). The only solution to this should be to try to configure this directly in the web Server?
Furthermore, I tried adding this to web.config, but it did not work either:
<customErrors mode="On" defaultRedirect="~/Home/Error">
<error statusCode="403" redirect="~/Home/Error" />
</customErrors>
Related
I have a .net mvc application(standard) and trying to implement custom errorhandling using httpErrors in web config.
<system.webServer>
<httpErrors errorMode="Custom" existingResponse="Replace" defaultResponseMode="Redirect">
<clear />
<error statusCode="404" path="http://localhost/E_HealthCare_Web/Views/Error/NotFound404" responseMode="Redirect" />
</httpErrors>
</system.webServer>
although it redirect to specified path but I get a http 403 error stating You do not have permission to view this directory or page. I think its an iis error but don't know how to solve it. if it needs a permission then where should I go to get the permission or should I set it up.
EDIT
as mentioned in the comment i tried using absolute Url and i got localhost redirected you too many times error and i tried clearing cookies as i tried clearing cookies but its not working and it is redirecting to the same page infinitely as you can see below.
Another Edit
Thanks to #LexLi and #JennyDai i finally solved this by changing my path in web.config to to path="http://localhost/E_HealthCare_Web/Error/NotFound404" by using mvc's proper route URL pattern.
Thanks to #LexLi and #JennyDai, I finally solved this by changing my path in web.config to to path="http://localhost/E_HealthCare_Web/Error/NotFound404" by using MVC's proper route URL pattern.
I'm getting a request like http://example.com/%2f..%2fwindows%2fsomething.ini and IIS is displaying "Forbidden URL - HTTP Error 403. The request URL is forbidden."
I think this request is getting blocked at the IIS level. How can I get IIS to let this error fall through to my application so I can show the error page the rest of my application uses? 404 errors fall through nicely as expected using the customErrors attribute in the web.config:
<customErrors mode="RemoteOnly" defaultRedirect="~/content/error.html">
</customErrors>
If I enter a simpler invalid URL like http://example.com/asdfasdfas/asdfasdf then my customErrors handler kicks in as desired.
403 is iis error. look like your asp.net error is not firing. you could try to add below code in the web.config file:
<httpErrors existingResponse="Replace" defaultResponseMode="ExecuteURL" errorMode="Custom">
<remove statusCode="403"/>
<error statusCode="403" path="/errorpage.aspx" responseMode="ExecuteURL"/>
you could also use iis manager to modify the changes:
1)open iis manager, select your site.
2)double click error pages.
3)set error page as suggested below or as per your requirement.
Why is IIS 7 showing me a default 403 page?
ASP MVC 5 - 403 customError not working
I'm developping my first MVC4 application and have now on several occasions gotten a 'Error loading page' message. This is nice if you're in a production environment but when developing an application it would be much more productive to see what's wrong, see the exception details. Is there some way or setting to get to the exception information wich causes this message ?
regards,
Jurjen.
It its a .Net exception locate the customErrorselement in your Web.config and set the attribute mode="Off" or mode="RemoteOnly".
If its a javascript error open your javascript console and watch for errors.
If its a .Net exception but the YSOD isn't rendered by the browser because it was requested via ajax, the fastet way to get to the output is to use a debugging proxy like fiddler and watch the html result there.
If its neither of the options, you have to provide more details.
Have you ever tried to run the application in the debugger?
You can enable debugging and set the error display mode in the web.config
<configuration>
<system.web>
<compilation debug="true" ...>
...
</compilation>
<customErrors mode="On|Off|RemoteOnly" ...>
(set this to Off or RemoteOnly) when debugging
...
</customErrors>
</system.web>
</configuration>
How to enable debugging for ASP.NET applications
How to set the customErrors Element
in _layout set
$.mobile.ajaxEnabled = false;
This solved my problem
Cheers
I have an ASP.NET MVC3 site where CustomErrors are set to Off in Web.config. Naturally, I want to set it to on. However, when setting it to on:
<customErrors mode="On" defaultRedirect="~/Error.aspx" />
accessing the site gives the error-page promptly.
Having it to Off doesn't give an error, and the site functions perfectly. Is there a silent error, that customErrors catches, but I don't see? Does it have something to do with me using session-variables?
This happens when deployed to IIS, but not in my dev-environment.
I have a MVC project set up with 3 areas. In the main project I have error handling set up
using custom errors in the web.config.
<customErrors mode="On" defaultRedirect="~/Error/HttpError">
<error statusCode="404" redirect="~/Error/Http404" /> </customErrors>
This cause the site to redirect to a error controller in the root and then show the error view.
This works OK in the root site, however when I throw an exception in the home controller of one
of the area sites it the message below.
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed.
Details: To enable the details of this specific error message to be viewable on the local server machine, please create a tag within a "web.config" configuration file located in the root directory of the current web application. This tag should then have its "mode" attribute set to "RemoteOnly". To enable the details to be viewable on remote machines, please set "mode" to "Off".
Is it the case that error handling in the root site cannot be used in the area sites?
Thanks
John.
Does the area have it's own web.config that might be setting it's own error handling options? Can you put a breakpoint in Application_OnError to see if another error is occuring (eg. one loading the error page - eg. if you've turned off Buffering, it won't be able to do the redirect)?
You could also try adding the something like this to the main web.config to see if it it makes any difference:
<location path="nameOfArea">
<system.web>
<customErrors mode="On" defaultRedirect="~/Error/HttpError" />
</system.web>
</location>