Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

How to handle exception in WebAPI in Asp.Net5

$
0
0

I tried handling the exception in webapi service by creating ExceptionAttribute, but looks like I am missing the reference to create the ExceptionFilterAttribute. I am getting the compiler error "type or namespace name 'HttpActionExecutedContext' could not be found" Am I missing any reference here? what is the correct way to handle exception in WebAPI in ASP.Net5? I searched in the internet but couldn't get the specific answer to asp.net5 - WebAPI

the following is the code for creating a ExceptionAttribute

using Microsoft.AspNet.Mvc.Filters;
using System;
using System.Net;
using System.Web.Http;
   public class ExceptionAttribute : ExceptionFilterAttribute
    {

        public override void OnException(HttpActionExecutedContext actionExecutedContext)
        {
            HttpStatusCode status = HttpStatusCode.InternalServerError;
            String message = String.Empty;
            var exceptionType = actionExecutedContext.Exception.GetType();

            .....

        }
    }

Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>