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
Related
There are many people on stack overflow asking to solve this question but there is no solution that has worked. My application is an MVC and a Web Api. Testing locally on Visual Studio works fine.
However, when i deploy it, it gives me the error, No MediaTypeFormatter is available to read an object of type 'IEnumerable1' from content with media type 'text/html'.
Exception Details: System.Net.Http.UnsupportedMediaTypeException: No MediaTypeFormatter is available to read an object of type 'IEnumerable`1' from content with media type 'text/html'.
Here is the code below.
WebApiClient.BaseAddress = new Uri("https://myweburl/WEBAPI/api/");
WebApiClient.DefaultRequestHeaders.Clear();
WebApiClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//WebApiClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/html"));
I don't understand why the error says the server puts out text/html. But when i tested it locally and it is JSON formatting.
Does anyone know if it is a result of net target framework as well? This is running the NET target framework of 4.6.1 for both the web api and mvc. I changed my information in the web.config to 4.0 but it didn't work as well.
<system.web>
<customErrors mode="Off" />
<compilation targetFramework="4.6.1" debug="true" />
<httpRuntime targetFramework="4.6.1" />
</system.web>
Basically, there was a firewall denying my permissions and generating the text/HTML instead of querying from the database. However, there is little support to be able to figure out what is the error. My suggestion is to print out the information that is being passed through from the Web Api and then see if it a permission denied by the firewall.
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>
The error states:
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 remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
Here's the address where you can see the error:
http://connellchamberofcommerce.com/
I have a feeling there's something in the web.config I'm supposed to change now that the website is online instead of my local machine, but this is my first ASP.Net website and I don't know what it is.
Is there something simple I'm missing that you're supposed to do when publishing an ASP.Net website?
In order to diagnose errors for your initial deployment, you can make the following change to your web.config.
<configuration>
...
<system.web>
...
<customErrors mode="Off" />
...
</system.web>
...
</configuration>
You should change this back to RemoteOnly when you have resolved all your deployment exceptions to prevent unsavory folks from learning too much about your architecture.
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>
My ASP.NET MVC application is within a folder called Stuff within IIS 6.0 webroot folder. So I access my pages as http://localhost/Stuff/Posts. I had EMLAH working while I was using the in-built webserver of Visual Studio. Now when I access http://localhost/Stuff/elmah.axd, I get resource not found error. Can anyone point my mistake here! Here is config file entry,
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/> //Handler
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah"/>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah"/> //Module
Working with IIS7 I found I needed both sections of the web.config populated (system.web AND system.webServer) - see Elmah not working with asp.net site.
Perhaps this is related.
Have you added an ignore *.axd routes in global.asax?
For Elmah, we need to differentiate between two things:
First the http modules doing all the work of error logging, emailing...etc.
Second, the http handlers, displaying the error log page and other pages (rss...etc.)
I was having the same problem of 404 resource not found because I have a weird setup!
on my development machine, (windows 7, iis 7 ) elmah was working like a charm because the application pool was working in the integrated pipeline mode. In the production machine, however, the application was using the managed pipeline and I tried all my best to make elmah work but it was all useless...
I then got the idea of displaying the UI (error log page, rss, error detail,...) using regular aspx pages.
I downloaded the source code, made some changes (sorry Atif, I was forced to do this because I needed the quickest solution) and then in my application , I created a folder under which I created regular aspx pages which inherits from Elmah defined pages.
The page only contains one line (ex: for the detail page: <%# Page Language="C#" Inherits ="Elmah.ErrorDetailPage"%>)
Now, I was able to run Elmah regardless of IIS 6/7 and it is working like a charm.. and It saved me from a big headache of correctly configuring http handlers and troubleshooting its work! additionally, configuring security is much simpler!
I don't know if the community is interested in this solution (If so, I am ready to post my full changes).
Hope that this gives you an idea on how to solve the problem in an alternative way (and if you need the modified dll with complete instructions on how to use it, just tell me!)
In the application pool settings in IIS set Managed Pipelin Mode to Classic if you don't want to change code or the web.config file. Your axd.s will then work as before.
Can you post the rest of your web.config?
Or, if you're comfortable enough, can you just ensure that the httpHandlers and httpModules (NOT handlers and modules) sections are filled in properly in the web.config?