当前位置: 首页>>代码示例>>C#>>正文


C# ExceptionHandling.ExceptionHandlerContext类代码示例

本文整理汇总了C#中System.Web.Http.ExceptionHandling.ExceptionHandlerContext的典型用法代码示例。如果您正苦于以下问题:C# ExceptionHandlerContext类的具体用法?C# ExceptionHandlerContext怎么用?C# ExceptionHandlerContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ExceptionHandlerContext类属于System.Web.Http.ExceptionHandling命名空间,在下文中一共展示了ExceptionHandlerContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleAsyncCore

        private static async Task<HttpResponseMessage> HandleAsyncCore(IExceptionHandler handler,
            ExceptionHandlerContext context, CancellationToken cancellationToken)
        {
            Contract.Assert(handler != null);
            Contract.Assert(context != null);

            await handler.HandleAsync(context, cancellationToken);

            IHttpActionResult result = context.Result;

            if (result == null)
            {
                return null;
            }

            HttpResponseMessage response = await result.ExecuteAsync(cancellationToken);

            if (response == null)
            {
                throw new InvalidOperationException(Error.Format(SRResources.TypeMethodMustNotReturnNull,
                    typeof(IHttpActionResult).Name, "ExecuteAsync"));
            }

            return response;
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:25,代码来源:ExceptionHandlerExtensions.cs

示例2: Handle

 // Create the error info object to be returned to the requestor
 public override void Handle(ExceptionHandlerContext context)
 {
     context.Result =
         new ResponseMessageResult
         (context.Request.CreateResponse(HttpStatusCode.InternalServerError,
         new ErrorInfo { Message = context.Exception.Message, Timestamp = DateTime.Now }));
 }
开发者ID:peteratseneca,项目名称:dps907fall2015,代码行数:8,代码来源:HandleError.cs

示例3: ShouldHandle

 public virtual bool ShouldHandle(ExceptionHandlerContext context)
 {
     //WebAPI v2 does not use IsOutermostCatchBlock anymore
     //IsOutermostCatchBlock does not exists. Use CatchBlock.IsTopLevel instead:
     //http://stackoverflow.com/a/22357634/1616023
     return context.ExceptionContext.CatchBlock.IsTopLevel;
 }
开发者ID:huoxudong125,项目名称:HQF.Tutorial.WebAPI,代码行数:7,代码来源:DemoExceptionHandler.cs

示例4: Handle

        private static void Handle(ExceptionHandlerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            ExceptionContext exceptionContext = context.ExceptionContext;
            Contract.Assert(exceptionContext != null);
            Exception exception = exceptionContext.Exception;

            HttpRequestMessage request = exceptionContext.Request;

            if (request == null)
            {
                throw new ArgumentException(Error.Format(SRResources.TypePropertyMustNotBeNull,
                    typeof(ExceptionContext).Name, "Request"), "context");
            }

            if (exceptionContext.CatchBlock == ExceptionCatchBlocks.IExceptionFilter)
            {
                // The exception filter stage propagates unhandled exceptions by default (when no filter handles the
                // exception).
                return;
            }

            context.Result = new ResponseMessageResult(request.CreateErrorResponse(HttpStatusCode.InternalServerError,
                exception));
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:29,代码来源:DefaultExceptionHandler.cs

示例5: Handle

        public override void Handle(ExceptionHandlerContext context)
        {
            bool shouldHandle = this.ShouldHandle(context);
            if (!shouldHandle)
            {
                return;
            }

            ErrorContext errorContext = null;

            try
            {
                errorContext = ErrorContextService.Resolve(context);

                var model = new ErrorViewModel(errorContext, context.RequestContext.RouteData.Values);
                var jsonModel = model.ToJson();

                var response = context.Request.CreateResponse(errorContext.HttpStatusCode, jsonModel);

                context.Result = new ResponseMessageResult(response);
            }
            finally
            {
                ErrorContextService.Log(CurrentLogger, errorContext);
            }
        }
开发者ID:sebnilsson,项目名称:WikiDown,代码行数:26,代码来源:WikiDownWebApiExceptionHandler.cs

示例6: HandleAsync

        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public virtual Task HandleAsync(ExceptionHandlerContext context, CancellationToken cancellationToken)
        {
            var info = ExceptionDispatchInfo.Capture(context.Exception);
            info.Throw();

            return Task.FromResult(0);
        }
开发者ID:PowerDMS,项目名称:Owin.Scim,代码行数:13,代码来源:OwinScimExceptionHandler.cs

示例7: Handle

 public override void Handle(ExceptionHandlerContext context)
 {
     if (context.Exception is Code.ExceptionResponse)
     {
         Code.ExceptionResponse ex = context.Exception as Code.ExceptionResponse;
         context.Result = new TextPlainErrorResult
         {
             Request = context.ExceptionContext.Request,
             Content = Transfer.Response.Error(ex.Message)
         };
     }
     else if (context.Exception is Code.ExceptionMaintenance)
     {
         context.Result = new TextPlainErrorResult
         {
             Content = Transfer.Response.Maintenance("Server is down for maintenance")
         };
     }
     else
     {
         context.Result = new TextPlainErrorResult
         {
             Request = context.ExceptionContext.Request,
             Content = Transfer.Response.Error(context.Exception.Message)
         };
     }
 }
开发者ID:Dezzles,项目名称:DexComplete,代码行数:27,代码来源:ExceptionHandler.cs

示例8: Handle

        public override void Handle(ExceptionHandlerContext context)
        {
            HttpRequestMessage request = context.Request;


            context.Result = new ResponseMessageResult(request.CreateResponse(HttpStatusCode.InternalServerError, new ErrorMsg(context.Exception.Message)));
        }
开发者ID:charla-n,项目名称:ManahostManager,代码行数:7,代码来源:ExceptionManahostHandler.cs

示例9: HandleAsync

 public Task HandleAsync(ExceptionHandlerContext context, CancellationToken cancellationToken)
 {
     // For exceptions at the top of the call stack, Result will start out non-null (due to
     // LastChanceExceptionHandler). This class does not force exceptions back to unhandled in such cases, so it
     // will not not trigger the host-level exception processing, such as the ASP.NET yellow screen.
     return TaskHelpers.Completed();
 }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:7,代码来源:EmptyExceptionHandler.cs

示例10: HandleValidationException

 private void HandleValidationException(ExceptionHandlerContext context)
 {
     context.Result = new GlobalExceptionResponse(context.ExceptionContext.Request, HttpStatusCode.BadRequest)
     {
         Message = context.Exception.Message
     };
 }
开发者ID:wongatech,项目名称:HealthMonitoring,代码行数:7,代码来源:GlobalExceptionHandler.cs

示例11: Handle

        public override void Handle(ExceptionHandlerContext context)
        {
            var exception = context.Exception;
            var httpException = exception as HttpException;
            if (httpException != null)
            {
                context.Result = new SimpleErrorResult(context.Request, (HttpStatusCode)httpException.GetHttpCode(),
                    httpException.Message);
                return;
            }

            if (exception is RootObjectNotFoundException)
            {
                context.Result = new SimpleErrorResult(context.Request, HttpStatusCode.NotFound,
                exception.Message);
                return;
            }
            if (exception is ChildObjectNotFoundException)
            {
                context.Result = new SimpleErrorResult(context.Request, HttpStatusCode.Conflict,
                exception.Message);
                return;
            }
            context.Result = new SimpleErrorResult(context.Request, HttpStatusCode.InternalServerError, exception.Message);
        }
开发者ID:srihari-sridharan,项目名称:Programming-Playground,代码行数:25,代码来源:GlobalExceptionHandler.cs

示例12: Handle

        public override void Handle(ExceptionHandlerContext context)
        {
            // get base exception
            var baseExp = context.Exception.GetBaseException();

            // set the result
            context.Result = new InternalServerErrorPlainTextResult(baseExp.Message, context.Request);
        }
开发者ID:GBmono,项目名称:GBmonoV1.0,代码行数:8,代码来源:GenericExceptionHandler.cs

示例13: Handle

        /// <summary>
        /// 在衍生類別中覆寫時,同步處理例外狀況。
        /// </summary>
        /// <param name="context">例外狀況處理常式內容。</param>
        public override void Handle(ExceptionHandlerContext context)
        {
            IError error = ErrorFactory.GetExceptionType(context);

            context.Result = new ResponseMessageResult(error.GenerateExceptionMessage(context));

            base.Handle(context);
        }
开发者ID:RayChiu0505,项目名称:etproject-crm,代码行数:12,代码来源:ErrorHandler.cs

示例14: HandleAsync

        public Task HandleAsync(ExceptionHandlerContext context, CancellationToken cancellationToken)
        {
            var jsonResult = "Error Global";

            context.Result = new ResponseMessageResult(new HttpResponseMessage { StatusCode = HttpStatusCode.InternalServerError, Content = new StringContent(jsonResult) });

            return Task.FromResult(0);
        }
开发者ID:jango2015,项目名称:WebApiBearerToken,代码行数:8,代码来源:APIErrorHandler.cs

示例15: Handle

 /// <summary>
 /// Format the result of the error context to be send back.
 /// </summary>
 /// <param name="context"></param>
 public override void Handle(ExceptionHandlerContext context)
 {
     context.Result = new TextPlainErrorResult
     {
         Request = context.ExceptionContext.Request,
         Content = $"We apologize but an unexpected error occurred. Please try again later. {context.Exception.Message}"
     };
 }
开发者ID:TheGapFillers,项目名称:Auluxa,代码行数:12,代码来源:AuluxaExceptionHandler.cs


注:本文中的System.Web.Http.ExceptionHandling.ExceptionHandlerContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。