WebApi IExceptionFilter

        public class ExceptionFilter : System.Web.Http.Filters.IExceptionFilter
        {
            bool IFilter.AllowMultiple => true;

            Task IExceptionFilter.ExecuteExceptionFilterAsync(HttpActionExecutedContext actionExecutedContext, CancellationToken cancellationToken)
            {
                var ex = actionExecutedContext.Exception;
                actionExecutedContext.Response = new System.Net.Http.HttpResponseMessage() ;

                actionExecutedContext.Response.Content = new System.Net.Http.ObjectContent(typeof(ReplyPack<string>),
                   new ReplyPack<string> { Status = 500, Msg = ex.Message, Value = null },
                    new JsonMediaTypeFormatter());

                return Task.FromResult(0);
            }
        }
            config.Filters.Add(new ExceptionFilter());

 

WebApi IExceptionFilter

上一篇:Windows系统中下载Earthdata数据 2


下一篇:Win32 sdk 下树形控件响应鼠标单击与双击,获得选中项的名称