當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。