Why Elmah set 0 for code in internal errors? - asp.net-mvc

Recently I created an ASP.NET MVC 5 application and installed Elmah.MVC.2.1.2 from the nugget package management on it.
Every things looks OK and Elmah logs all errors but when it logs internal errors it set 0 for code. I think it should set 5xx error code for theirs, am I right or not? If I'm right, where should I configure it?
Thanks in advanced (:

ELMAH only shows the status code, if the thrown exception is of type HttpException. You can either catch the exception inside the controller and re-throw it as a HttpException or write a filter converting uncaught exceptions to HttpException.

Related

ELMAH --Is There a way to identify from Error log Unhandled or userHandled?

Am using ELMAH and want to know if the Error reported by ELMAH is Unhandled or it is handled in code and logged
ErrorSignal.FromCurrentContext().Raise(context.Exception);
Is there a way to identify it ?
Might be a simple but just curious to know
Thanks
Instead of using ErrorSignal.FromCurrentContext().Raise I use ErrorLog.GetDefault().Log. There is a nice example in log4net elmah appender source code.

Exceptions in N2cms page

i'm using n2cms + asp.net mvc,
when the site is uploaded to a webserver, and an exception is thrown in the aspx page, the page appear blank, and there is nothing in the page, even if i turned off the CustomErrors in web.config
but when the site is running on my computer visual studio simply show me the exception,
is there a way to catch the exception in this situation?
This may be due to your hosting configuration. You could take a look at ELMAH for an easy way of logging exceptions.
You can handle all global errors in your Global.asax's method called Application_Error - http://msdn.microsoft.com/en-us/library/24395wz3.aspx . It will work for simple cases. But I strongly recommend to use ELMAH
N2CMS makes calls to SwallowExceptions(). This is why you are receiving a blank page instead of an exception. You could look for that method call and comment it.

Why are users taken to /?aspxerrorpath=/UrlRouting.axd

I was just looking at analytics for an ASP.NET MVC 1 site running on Mono.
I saw that once in a while users are brought to this URL: /?aspxerrorpath=/UrlRouting.axd
What would cause this?
an error?
/
is your error handler
/UrlRouting.axd
threw the exception.
Look at your customErrors section in web.config
Unless you are clearing all the items in your HttpContext.Items (not common), the error is occurring between the two HttpApplication events PostResolveRequestCache and PostMapRequestHandler. The only event between them is MapRequestHandler. You can probably find the cause of this error by looking for any HttpModules that subsribe to the MapRequestHandler event.

set switch to trigger custom filter in asp.net mvc for exception handling

is there something I need to "turn on" to allow my asp.net mvc application to utilize custom exception filters?
I posted in here last week with code samples to a custom filter I wrote that should catch and handle a custom exception but for some reason I keep getting an error on my throw line indicating that the exception was not handled by user code.
I had a response last week from someone who indicated they copied and pasted my code exactly and it worked fine for them. This makes me wonder if maybe I need to set something web.config or something to tell the app to use the custom filter for unhandled exceptions.
please advise,
TIA
How are you implementing? If you inherit from FilterAttribute and IExceptionFilter class/interface, you will have to ensure the exception content has the exceptionhandled flag set to true to prevent the error, I believe.

ASP.NET MVC Unhandled Exceptions on Images?

I haven't been able to replicate the exception when I browse my site... but I found out about this through my event logger (it emails my cell phone when an unhandled exception occurs).
Here's the exception:
The controller for path
'/Content/UsrImg/ImageFileName.jpg'
could not be found or it does not
implement IController.
What I think happened is that the image that Google (or perhaps a proxy server) had cached no longer existed. When trying to go directly to that image, it load the "Page not found" friendly error I wrote.
But should it be throwing an unhandled exception on 404 errors? Seems a bit strange to me. Perhaps there something I can do in the routing to fix this?
I just ran into this issue yesterday. Check to see if the image is on your server. My problem was Build Action for the file was set to none, but it should be set to Content. It was not including the file when I published the website.
You don't need to change routing, as the Content directory should be invoke Routing.

Resources