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.
Related
I have project with set of subdomain websites (.NET MVC).
e.g.
admin.example.com
weather.example.com
test.example.com
error.example.com
All this websites have same style and work as one big project, so my idea is to create one place for error pages as subdomain website (error.example.com). I think that in that case I will get one place where I will support my error pages (design, styling and other things).
My question is how to do that using MVC tools and web.config.
P.S.
Also it will be cool to have one place to log exceptions. For now I'm using elmah to log all exception in database.
It is not a usual thing, so I have a workaround.
I used Application_Error of Global.asax to track redirect.
I'm coming at the end of the development of my application.
Everything is working fine, but if once somebody got an unexpected exception, I would like to be able to:
Redirect him to a user-friendly page explaining that we got a problem.(Specifying a controller/action)
Log every information of the stack trace, current controller/action, parameter, session data, ...
What is the best way to do it with asp.net MVC?
EDIT
In complement of the great answer:
I integrated elmah like described here: http://joel.net/logging-errors-with-elmah-in-asp.net-mvc-3--part-1--setup
And then I specified some custom error page. So now I've all I need!
I would recommend you use "Elmah" http://code.google.com/p/elmah/
This package is a godsend - does exactly what is shown on the box, with close to ZERO changes to your source code.
It is also available via NuGet at http://nuget.org/packages/elmah
Use action filters.
http://blogs.msdn.com/b/gduthie/archive/2011/03/17/get-to-know-action-filters-in-asp-net-mvc-3-using-handleerror.aspx
You can catch errors in the global.asax. There is a method protected void Application_Error(object sender, EventArgs e) where you can do what ever you want.
Take a look at PostSharp, neat and easy to use. Starter version available to use after free registration. NuGet package also available http://nuget.org/packages/PostSharp
I have implemented Elmah in one of my ASP.NET MVC projects. In addition I did the following:
I implemented the ElmahHandleErrorAttribute written by Atif Aziz in this post
I added the attribute to all my controllers
I have setup Elmah to filter out 404 errors since I do not want to log those
I added an Error.aspx view in the Shared folder that I wish to use for all my errors.
My customErrors in the Web.Config are turned on and I have not specifed any error pages in it as I shouldn't have to.
In one of my controllers I have the following code:
if (model == null)
throw new HttpException((int)HttpStatusCode.NotFound, "Project not found");
I simply want to display a 404 if a record can not be found in the database. For some reason my Error.aspx page will not display for a 404 error. Instead it displays the generic asp.net "the resource can not be found" page. I have tried to remove the 404 filter setup in Elmah but that does not change anything.
The interesting part is if I change the error from NotFound to say InternalServerError the Error.aspx page shows up just fine.
Does anyone have any pointers as to why this is?
I have not used Elmah beyond creating a sample app - but maybe because a 404 is not application error? If my understanding is correct, a 404 error gets pushed back to IIS which in turn displays the error message you are seeing. Also, I believe that the web.coin
If i understand correctly, you may want to amend your approach and build use this instead or set the Response.StatusCode to 404 (Check out Jeff's answer in the linked question)
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.
Unfortunately, I need to do this. I'm using ELMAH for my error log. Before I route to my error.aspx view, I have to grab the default ELMAH error log so I can log the exception. You used to be able to use
Elmah.ErrorLog.Default
However, this is now marked as obsolete. The compiler directs me to use the method
Elmah.ErrorLog.GetDefault(HttpContext context)
MVC's context is of type HttpContextBase, which enables us to mock it (YAY!). How can we deal with MVC-unaware libraries that require the old style HttpContext?
Try System.Web.HttpContext.Current. It should do the trick.
Gets HTTP-specific information about an individual HTTP request.
MSDN
this.HttpContext.ApplicationInstance.Context