2010-11-05 42 views
1

由於升級到ASP.NET MVC2,我們已經注意到了Windows應用程序事件日誌已滿的條目如下:防止Asp.net MVC2例外應用程序事件日誌

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. 

請求是壞的,所以我們得到這個錯誤。太好了,但我想在我的應用程序中處理這個問題,而不是讓它將事件日誌冒出來。有什麼建議麼?

編輯

看答案this question,這將是更明智的建立Route Constraints來處理這個問題呢?

回答

1

這不是特定於ASP.NET MVC的東西,但它是任何ASP.NET應用程序的正常行爲。所有未記錄的異常都會被記錄下所以你需要處理它們。對於這種類型的異常,您確實可以使用路由約束並具有自定義404和500錯誤頁面。

Global.asax中還有Application_Error處理程序可用於處理異常。對於控制器級異常,有[HandleError]操作過濾器。