spender
spender

Reputation: 120480

Preventing Asp.net MVC2 Exceptions in Application Event Log

Since upgrading to ASP.NET MVC2, we've noticed the Windows application event log is full of entries as follows:

Event code: 3005 
Event message: An unhandled exception has occurred. 
Event time: 11/4/2010 3:29:16 PM 
Event time (UTC): 11/4/2010 7:29:16 PM 
Event ID: 2039870297302976340236
Event sequence: 6422
Event occurrence: 864 
Event detail code: 0 

...
Exception information: 
Exception type: ArgumentException 
Exception message: The parameters dictionary contains a null entry for parameter 'someParam' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Index(System.String, Int32)' in 'SomeNameSpace.SomeController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.

The request is bad, so we're getting this error. Great, but I'd like to handle this in my application rather than allowing it to bubble out the event log. Any suggestions?

EDIT

Look at the answer to this question, would it be more sensible to set up Route Constraints to deal with this problem?

Upvotes: 1

Views: 443

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038930

This is not something specific to ASP.NET MVC but it is the normal behavior of any ASP.NET application. All unhanded exceptions are logged which seems normal. So you need to handle them. For this type of exception you could indeed use route constraints and have custom 404 and 500 error pages.

There's also the Application_Error handler in Global.asax which could be used to handle exceptions. For controller level exceptions there's the [HandleError] action filter.

Upvotes: 1

Related Questions