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
Related
I keep getting this error when trying to run my system
<system.web>
<customErrors mode="Off"/>
</system.web>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.html"/>
</system.web>
First of all, enable the details of this specific error message by putting the "customErrors" tag in your "web.config" file like this:
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
Now you will get the exact error in your code and you can fix that specific error.
For security reasons, your code will not be shown in the browser for end user until you have not enabled CustomError mode="Off" in web.config file.
For security reasons .NET-Websites shows complete exceptions only, if you call them locally. To see the error message you have to choices:
Call the website through a browser on the Server (of course not possible, if you deploy to a Azure WebApp, but e.g. in a VM)
Add the first of your snippets (customErrors mode="Off") to your web.config. Then you'll see the complete exception even remotly over the network. My advice would be to set it back to the default setting after you've seen and fixed the error.
Hey i have an mvc app that i have published in my azure server. I get an error when i try it in the server. In localhost in works fine. But in the server i get an error that looks like this
So my question is how can i remove that custom error. I want to see the error message that explains what the error is about?
i want the error message to be like this one
check if you have this line this line in your web config system.web area
<customErrors mode="Off" />
if you do change it to off and if not add it in
You can use web.config transform file (such as Web.Debug.config or Web.Release.config) and include the following section:
<system.web>
<customErrors mode="Off" xdt:Transform="Insert" />
</system.web>
The Web.config file will be transformed when you deploy to Azure. The transform does not occur locally.
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"
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
Please find attached the error I am getting while trying to display a custom error message. My application ASP.Net 4 and uses IIS 7.5. HEre is my code in web.config.
</httpErrors>
You should have your this under system.web
<system.web>
<customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/ErrorPages/WebError.aspx"/>
And this under system.webServer (one of a few options)
<system.webServer>
<httpErrors existingResponse="PassThrough"/>