【发布时间】:2016-01-30 10:55:49
【问题描述】:
我正在尝试为 ASP.NET Web api 编写一个全局错误处理程序,它能够记录在我的 api 中导致未处理异常的请求的请求详细信息。我已经在我的 OWIN 启动类中注册了以下 GlobalExceptionHandler 类,但我无法检索发布在请求正文中的任何数据的内容。
public class GlobalExecptionHander : ExceptionHandler
{
public override void Handle(ExceptionHandlerContext context)
{
var body = context.Request.Content.ReadAsStringAsync().Result;
//body here is an empty string
context.Result = new UnhandledErrorActionResult
{
Request = context.Request,
};
}
}
在我的创业课上
config.Services.Replace(typeof(IExceptionHandler), new GlobalExecptionHander());
【问题讨论】:
标签: asp.net asp.net-web-api asp.net-web-api2 owin