加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-web-api – IExceptionHandler的多个实现

发布时间:2020-12-16 03:29:58 所属栏目:asp.Net 来源:网络整理
导读:在WebAPI中处理IExceptionHandler的多个实现的最佳方法是什么? config.Services.Replace(typeof(IExceptionHandler),new ExceptionHandlerFilter());config.Services.Add(typeof(IExceptionHandler),new ValidationExceptionHandlerFilter()); 尝试注册多个
在WebAPI中处理IExceptionHandler的多个实现的最佳方法是什么?

config.Services.Replace(typeof(IExceptionHandler),new ExceptionHandlerFilter());
config.Services.Add(typeof(IExceptionHandler),new ValidationExceptionHandlerFilter());

尝试注册多个实现时,启动会抛出异常:

The service type IExceptionHandler is not supported.rnParameter name: serviceType

但API建议支持多个处理程序,因为有一个ShouldHandle属性要覆盖ExceptionHandler类.

解决方法

您无法注册更多IExceptionHandler

We support registering multiple exception loggers but only a single exception handler.

来源:Global Error Handling in ASP.NET Web API

ShouldHandle属性用于仅获取堆栈顶部的异常

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读