• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ActionExecutedContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: OnActionExecuted

        public override void OnActionExecuted(ActionExecutedContext context)
        {
            if (context.Exception != null)
            {
                context.Result = Helpers.GetContentResult(null, "Hi from Action Filter");

                context.Exception = null;
            }
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:9,代码来源:HandleExceptionActionFilter.cs


示例17: BuildActionExecuted

        public ActionExecutedContext BuildActionExecuted()
        {
            var actionExecutedContext = new ActionExecutedContext(
                actionContext, new List<IFilterMetadata>(), new { });
            actionExecutedContext.Result = result;
            actionExecutedContext.Exception = exception;

            return actionExecutedContext;
        }
开发者ID:brainwipe,项目名称:NJsonApi,代码行数:9,代码来源:FilterContextBuilder.cs


示例18: OnActionExecuted

        public override void OnActionExecuted(ActionExecutedContext context)
        {
            var result = context.Result as ObjectResult;
            if (result != null)
            {
                result.Formatters.Add(new CustomFormatter("application/FormatFilterController"));
            }

            base.OnActionExecuted(context);
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:10,代码来源:FormatFilterController.cs


示例19: OnActionExecuted

        public override void OnActionExecuted(ActionExecutedContext context)
        {
            var result = context.Result as ObjectResult;

            if (result != null)
            {
                result.Formatters.Add(new VCardFormatter_V3());
                result.Formatters.Add(new VCardFormatter_V4());
            }
        }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:10,代码来源:ProducesWithMediaTypeParametersController.cs


示例20: OnActionExecuted

        public override void OnActionExecuted(ActionExecutedContext context)
        {
            AlertsContainer current = JsonConvert.DeserializeObject<AlertsContainer>(TempData["Alerts"] as String ?? "");
            if (current == null)
                current = Alerts;
            else
                current.Merge(Alerts);

            TempData["Alerts"] = JsonConvert.SerializeObject(current);
        }
开发者ID:NonFactors,项目名称:MVC6.Template,代码行数:10,代码来源:BaseController.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ActionExecutingContext类代码示例发布时间:2022-05-24
下一篇:
C# ActionEventArgs类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap