I'm trying to redirect all my 404 errors to the Index page of my project.
But when I set my custom errors in web.config I get a Runtime Error that says:
"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. "
Here is my web.config errors block.
<customErrors mode="On" redirectMode="ResponseRewrite" >
<error statusCode="404" redirect="~/" />
</customErrors>
I would appreciate any suggestions how to debug and fix it.
Your redirect is empty. Try adding a new custom error page and change the redirect to something like redirect="~/Controller/CustomerErrorPage"
Related
I am using the below code to display the 404 custom error page.
<customErrors mode="On">
<error statusCode="403" redirect="../403.htm" />
<error statusCode="404" redirect="Unsecure/404.html" />
</customErrors>
i am trying to use the below url's after i hosted
www.abc.com/login.aspx is my original url but when i use www.abc.com/kdfjdkfjd.aspx i am able to see the 404 page but when i am trying to use the url www.abc.com/login.apsx.(fullstop is added at the end) i am getting the below error
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.
I have hosted this in window 2008 server R2.
Below url works fine and redirects to the custom error page for page not found.
http://localhost:50298/a/b/c
But when the Url is longer like the below one
http://localhost:50298/a/b/c/d
then it shows the default error page instead of showing the custom error page with message "HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
In the web.config below is added . It works fine for shorter url with max 3 "/" but it doesn't works when it is more than 3.
</system.web>
<customErrors mode="On" defaultRedirect="~/Error/Index">
<error statusCode="404" redirect="~/Error/NotFound"/>
</customErrors>
</system.web>
Is there any setting required to be done to show the custom error page for longer urls instead of the default iis error page ?
I have a MVC ASP.NET website in which I have the following on the web.config
<customErrors mode="On" defaultRedirect="~/Views/Shared/Error.cshtml">
<error statusCode="404" redirect="~/redir/Home/Http404" />
</customErrors>
So when I try to navigate to an address that does not exist I get my Http404 view located under Home which is correct.
Now I have a special situation in which I want to manually return the same Http 404 and I am seeing the IIS 8 error instead of my Http404 view.
Controller :
return new HttpNotFoundResult();
How to avoid this IIS8 error page, and still make my view the error provider?
EDIT*
I found out that if instead of HttpNotFoundResult() I use the old throw new HttpException(404, "HTTP/1.1 404 Not Found"); it works.
Why this difference ?
Thanks
The <customErrors> section is aimed to control the behavior when an Application Error occurs. That's also why it's defined under the <system.web> section.
When you explicitly throw an HttpException (or when any other internal exception occurs) the <customErrors> settings will be used as it's considered (rightfully) an application error.
On the other hand, when you simply return HttpNotFoundResult(), no application error is being thrown (internally, it just sets the HTTP response status code and message to 404) and the MvcHandler will hand over the request to the next handler in the pipeline. So you eventually end up with a regular Server Error that is handled by IIS just like any other '404 not found' request, and the <customErrors> section does not affect its behavior.
So, you need to control IIS behavior when regular server error occurs. To do this, use the <system.webServer/httpErrors> section as follows:
<system.webServer>
<httpErrors errorMode="Custom">
<remove statusCode="404"/>
<error statusCode="404" path="/redir/Home/Http404" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
See Documentation
I am looking for a way to catch an error caused by an incorrect web.config file.
It looks like void Application_Error(object sender, EventArgs ev) is only called after validating the config file and is never reached.
Example error:
Parser Error Message: Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive.
This error happens when the application's App pool is set to framework 2.0 instead of 4.0
When this error happens I want to redirect to a specific page with screenshots to explain how to change the App pool.
Is it possible to catch this error in global.asax?
try this solutuin
<configuration>
<system.web>
<customErrors defaultRedirect="GenericError.htm" mode="RemoteOnly">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
</system.web>
</configuration>
for more detail http://msdn.microsoft.com/en-us/library/h0hfz6fc(v=vs.71).aspx
in my C# code I use try/catch on all my methods, this picks up most of the errors, but some errors like 404 are not picked up.
Does anyone know how to pick up all other errors that occur on the server or if SQL server is down?
thanks
you should use ELMAH as error handler in your project...read the link for more details.
You can update your web.config file and specify the following:
<customErrors mode="On">
<error statusCode="404" redirect="~/error404.aspx" />
</customErrors>