防止应用程序事件日志中出现 Asp.net MVC2 异常

发布于 2024-09-30 18:26:28 字数 1098 浏览 6 评论 0原文

自从升级到 ASP.NET MVC2 以来,我们注意到 Windows 应用程序事件日志充满了如下条目:

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.

请求错误,因此我们收到此错误。很好,但我想在我的应用程序中处理这个问题,而不是让它冒泡出事件日志。有什么建议吗?

编辑

看看这个问题的答案,设置路由约束<会更明智吗/a> 处理这个问题?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸢与 2024-10-07 18:26:28

这不是 ASP.NET MVC 特有的行为,而是任何 ASP.NET 应用程序的正常行为。所有未处理的异常都会被记录,这看起来很正常。所以你需要处理它们。对于这种类型的异常,您确实可以使用路由约束并自定义 404 和 500 错误页面。

Global.asax 中还有 Application_Error 处理程序,可用于处理异常。对于控制器级别的异常,有 [HandleError]< /code>动作过滤器。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文