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


C# ActionExecutedContext类代码示例

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


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

示例1: OnActionExecuted

        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            ControllerBase controller = filterContext.Controller as ControllerBase;

              if (controller != null)
              {
            string serializedModelState = controller.TempData[Key] as string;

            if (!string.IsNullOrEmpty(serializedModelState))
            {
              IEnumerable<ModelStateWrapper> modelStateWrappers = JsonConvert.DeserializeObject<IEnumerable<ModelStateWrapper>>(serializedModelState, new JsonSerializerSettings() { Error = DeserializationErrorHandler });

              if (modelStateWrappers != null)
              {
            ModelStateDictionary modelState = new ModelStateDictionary();

            foreach (ModelStateWrapper modelStateWrapper in modelStateWrappers)
            {
              ModelStateEntry ms = new ModelStateEntry();

              ms.ValidationState = modelStateWrapper.ValidationState;
              ms.AttemptedValue = modelStateWrapper.Value;
              modelState.Add(modelStateWrapper.Key, ms);
            }

            if (filterContext.Result is ViewResult)
              controller.ViewData.ModelState.Merge(modelState);

            else controller.TempData.Remove(Key);
              }
            }
              }

              base.OnActionExecuted(filterContext);
        }
开发者ID:rajendra1809,项目名称:Platformus,代码行数:35,代码来源:ModelStateTempDataTransferAttribute.cs

示例2: OnActionExecuted

        public override void OnActionExecuted(ActionExecutedContext context)
        {
            base.OnActionExecuted(context);

            if (context.Exception == null)
            {
                return;
            }

            var dbException = context.Exception as DbException;
            if (dbException != null)
            {
                context.Result = new BadRequestObjectResult(dbException);
            }
            else
            {
                context.Result = new InternalServerErrorResult();
            }

            var apiKey = this.config["RaygunSettings:ApiKey"];
            if (string.IsNullOrEmpty(apiKey))
            {
                return;
            }

            //TODO: update this once Raygun supports ASPNET CORE RTM
            //var settings = new RaygunSettings { ApiKey = apiKey };

            //var client = new RaygunClient(settings);
            //client.Send(context.Exception);
        }
开发者ID:SSWConsulting,项目名称:enterprise-musicstore-api-aspnet,代码行数:31,代码来源:MvcExceptionActionFilter.cs

示例3: OnActionExecuted

    public override void OnActionExecuted(ActionExecutedContext context) {
      var exception = context.Exception as CommandRejectedException;
      if (exception == null) return;

      context.Result = new BadRequestObjectResult(exception.Errors);
      context.ExceptionHandled = true;
    }
开发者ID:grrizzly,项目名称:eventsourced.net,代码行数:7,代码来源:Return400BadRequstIfCommandRejectedAttribute.cs

示例4: OnActionExecuted

        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            var controller = filterContext.Controller as Controller;

            var tempModelState = controller.TempData[Key] as string;
            if (tempModelState == null)
            {
                return;
            }

            Dictionary<string, List<string>> modelState = (Dictionary<string, List<string>>)JsonConvert.DeserializeObject(
                tempModelState, typeof(Dictionary<string, List<string>>));

            if (modelState.Keys.Count > 0)
            {
                //Only Import if we are viewing
                if (filterContext.Result is ViewResult)
                {
                    foreach (var entry in modelState)
                    {
                        foreach (var error in entry.Value)
                        {
                            controller.ViewData.ModelState.AddModelError(entry.Key, error);
                        }
                    }
                }
                else
                {
                    //Otherwise remove it.
                    controller.TempData.Remove(Key);
                }
            }

            base.OnActionExecuted(filterContext);
        }
开发者ID:mperrenoud,项目名称:packt,代码行数:35,代码来源:ActionFilters.cs

示例5: OnActionExecuted

        /// <summary>
        /// アクションが実行されたとに呼び出されます。
        /// </summary>
        /// <param name="context">実行コンテキスト</param>
        public override void OnActionExecuted(ActionExecutedContext context)
        {
            base.OnActionExecuted(context);

            //--- 例外が飛んだ場合は握り潰してエラーを通知
            if (context.Exception != null)
            {
                var color = "#C00000";
                context.Result = this.Json(new Message
                {
                    Text = "Unhandled exception occured...",
                    IsEphemeral = true,
                    Attachments = new []
                    {
                        new Attachment
                        {
                            Color      = color,
                            AuthorName = "Type",
                            AuthorLink = Uri.EscapeUriString($"https://www.google.com/search?q={context.Exception.GetType()}"),
                            Text       = context.Exception.GetType().ToString(),
                        },
                        new Attachment
                        {
                            Color      = color,
                            AuthorName = nameof(context.Exception.Message),
                            Text       = context.Exception.Message,
                        },
                        new Attachment
                        {
                            Color      = color,
                            AuthorName = nameof(context.Exception.StackTrace),
                            Text       = context.Exception.StackTrace,
                        },
                        new Attachment
                        {
                            Color      = color,
                            AuthorName = nameof(context.Exception.InnerException),
                            Text       = context.Exception.InnerException?.Message,
                        },
                    }
                });
                context.ExceptionHandled = true;
            }

            //--- JSON を返していれば正常終了とみなす
            if (context.Result is JsonResult)
                return;

            //--- ステータスコードを持つ場合はそれを通知
            var message = "Error occured...";
            var result = context.Result as HttpStatusCodeResult;
            if (result != null)
                message += Environment.NewLine + $"[HTTP Status Code : {result.StatusCode}]";

            context.Result = this.Json(new Message
            {
                Text = message,
                IsEphemeral = true,
            });
        }
开发者ID:xin9le,项目名称:ApisFlorea,代码行数:64,代码来源:SlashCommandsController.cs

示例6: OnActionExecuted

        public override void OnActionExecuted(ActionExecutedContext context)
        {
            if (context.Result == null || context.Result is NoContentResult)
            {
                return;
            }

            if (BadActionResultTransformer.IsBadAction(context.Result))
            {
                var transformed = BadActionResultTransformer.Transform(context.Result);

                context.Result = new ObjectResult(transformed)
                {
                    StatusCode = transformed.Errors.First().Status
                };
                return;
            }

            var responseResult = (ObjectResult)context.Result;
            var relationshipPaths = FindRelationshipPathsToInclude(context.HttpContext.Request);

            if (!configuration.ValidateIncludedRelationshipPaths(relationshipPaths, responseResult.Value))
            {
                context.Result = new HttpStatusCodeResult(400);
                return;
            }

            var jsonApiContext = new Context(
                new Uri(context.HttpContext.Request.GetDisplayUrl()),
                relationshipPaths);
            responseResult.Value = jsonApiTransformer.Transform(responseResult.Value, jsonApiContext);
        }
开发者ID:brainwipe,项目名称:NJsonApi,代码行数:32,代码来源:JsonApiActionFilter.cs

示例7: OnActionExecuted

 public override void OnActionExecuted(ActionExecutedContext context) {
     base.OnActionExecuted(context);
     var controller = context.Controller as Controller;
     if (controller != null) {
         controller.ViewData[ParsleyValidationAttributesGenerator.USE_PARSLEY_KEY] = true;
     }
 }
开发者ID:mburumaxwell,项目名称:Asp.Net5-ParsleyValidation,代码行数:7,代码来源:UseParsleyValidationAttribute.cs

示例8: OnActionExecuted

 public void OnActionExecuted(ActionExecutedContext context)
 {
     var time = _timer.ElapsedMilliseconds;
     context.HttpContext.Response.Headers.Add(
         "ActionElapsedTime",
         new string[] { time.ToString(CultureInfo.InvariantCulture) + " ms" });
 }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:7,代码来源:SimplePocoController.cs

示例9: OnActionExecuted

        /// <inheritdoc />
        public void OnActionExecuted(ActionExecutedContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var httpResponseException = context.Exception as HttpResponseException;
            if (httpResponseException != null)
            {
                var request = context.HttpContext.GetHttpRequestMessage();
                var response = httpResponseException.Response;

                if (response != null && response.RequestMessage == null)
                {
                    response.RequestMessage = request;
                }

                var objectResult = new ObjectResult(response)
                {
                    DeclaredType = typeof(HttpResponseMessage)
                };

                context.Result = objectResult;

                // Its marked as handled as in webapi because an HttpResponseException
                // was considered as a 'success' response.
                context.ExceptionHandled = true;
            }
        }
开发者ID:cemalshukriev,项目名称:Mvc,代码行数:31,代码来源:HttpResponseExceptionActionFilter.cs

示例10: OnActionExecuted_HandlesExceptionAndReturnsObjectResult

        public void OnActionExecuted_HandlesExceptionAndReturnsObjectResult()
        {
            // Arrange
            var filter = new HttpResponseExceptionActionFilter();
            var httpContext = new DefaultHttpContext();
            httpContext.Request.Method = "GET";

            var actionContext = new ActionContext(
                                httpContext,
                                new RouteData(),
                                Mock.Of<ActionDescriptor>());

            var context = new ActionExecutedContext(
                actionContext,
                filters: new List<IFilter>(),
                controller: new object());

            context.Exception = new HttpResponseException(HttpStatusCode.BadRequest);

            // Act
            filter.OnActionExecuted(context);

            // Assert
            Assert.True(context.ExceptionHandled);
            var result = Assert.IsType<ObjectResult>(context.Result);
            Assert.Equal(typeof(HttpResponseMessage), result.DeclaredType);
            var response = Assert.IsType<HttpResponseMessage>(result.Value);
            Assert.NotNull(response.RequestMessage);
            Assert.Equal(context.HttpContext.GetHttpRequestMessage(), response.RequestMessage);
            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:31,代码来源:HttpResponseExceptionActionFilterTest.cs

示例11: OnActionExecuted

 public void OnActionExecuted(ActionExecutedContext context)
 {
     if (context.ActionDescriptor.DisplayName == "FiltersSample.Controllers.HomeController.Hello")
     {
         // Manipulating action result...
         context.Result = Helpers.GetContentResult(context.Result, "FIRST: ");
     }
 }
开发者ID:ColinDabritz,项目名称:Docs,代码行数:8,代码来源:SampleGlobalActionFilter.cs

示例12: IsValidResult

        private bool IsValidResult(ActionExecutedContext context)
        {
            var contextResult = context.Result;

            return contextResult is RedirectResult ||
                contextResult is RedirectToRouteResult ||
                contextResult is RedirectToActionResult;
        }
开发者ID:ankn85,项目名称:apex,代码行数:8,代码来源:ExportModelStateAttribute.cs

示例13: OnActionExecuted

 public void OnActionExecuted(ActionExecutedContext context)
 {
     context.Result = new ContentResult()
     {
         Content = "4",
         ContentType = new MediaTypeHeaderValue("text/plain")
     };
 }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:8,代码来源:RandomNumberFilter.cs

示例14: OnActionExecuted

 public void OnActionExecuted(ActionExecutedContext context)
 {
     context.Result = new ContentResult()
     {
         Content = "4",
         ContentType = "text/plain"
     };
 }
开发者ID:ymd1223,项目名称:Mvc,代码行数:8,代码来源:RandomNumberFilter.cs

示例15: OnActionExecuted

        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            var model = ((Controller)filterContext.Controller).ViewData.Model;

            object viewModel = Mapper.Map(model, SourceType, DestType);

            ((Controller)filterContext.Controller).ViewData.Model = viewModel;
        }
开发者ID:Supermakaka,项目名称:mvc6,代码行数:8,代码来源:AutoMap.cs


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