开发者

Preventing Asp.net MVC2 Exceptions in Application Event Log

开发者 https://www.devze.com 2023-01-23 21:45 出处:网络
Since upgrading to ASP.NET MVC2, we\'ve noticed the Windows application event log is full of entries as follows:

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 sugg开发者_开发百科estions?

EDIT

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消