Disable *all* exception handling in ASP.NET Web API 2 (to make room for my own)?

前端 未结 5 2043
隐瞒了意图╮
隐瞒了意图╮ 2020-12-02 12:21

I want to wire up exception handling in a middleware component, something like this:

public override async Task Invoke(IOwinContext context)
{
    try
    {
         


        
5条回答
  •  余生分开走
    2020-12-02 13:00

    OWIN is not supposed to handle exceptions like that because web api has its own error handling built in. OWIN is designed to be separate from the application. If you set a breakpoint on the HandleAsync method of your exception handler, you should be able to inspect the context variable and see the details of the exception.

    If you are trying to do this just for debugging purposes, setting your breakpoint there should allow you to see the exception. If you need to log the exceptions, the exception handler is the best place to do that, in my opinion.

    Hope that helps.

提交回复
热议问题