public override void OnResultExecuting(ResultExecutingContext context)
 {
     context.Result = new ContentResult
     {
         Content = "The Result was never executed"
     };
 }
 public override void OnResultExecuting(ResultExecutingContext context)
 {
     context.HttpContext.Response.Headers["Cache-Control"] = "no-cache, no-store, max-age=0";
     context.HttpContext.Response.Headers["Pragma"] = "no-cache";
     context.HttpContext.Response.Headers["Expires"] = "-1";
     base.OnResultExecuting(context);
 }
 public override void OnResultExecuting(ResultExecutingContext context)
 {
     if (context.ActionDescriptor.DisplayName == "FiltersWebSite.ProductsController.GetPrice")
     {
         context.HttpContext.Response.Headers.Append("filters",
             "On Action Result Filter - OnResultExecuting");
     }
 }
        public override void OnResultExecuting(ResultExecutingContext context)
        {
            var objResult = context.Result as ObjectResult;
            var dummyClass = objResult.Value as DummyClass;
            dummyClass.SampleInt = 120;

            objResult.Formatters.Add(new XmlSerializerOutputFormatter());

            base.OnResultExecuting(context);
        }
        public void OnResultExecuting(ResultExecutingContext context)
        {
            if (context.ActionDescriptor.DisplayName == "FiltersWebSite.ResultFilterController.GetHelloWorld")
            {
                context.Result = Helpers.GetContentResult(context.Result, "GlobalResultFilter.OnResultExecuting");
            }

            if (context.ActionDescriptor.DisplayName == "FiltersWebSite.ProductsController.GetPrice")
            {
                context.HttpContext.Response.Headers.Append("filters",
                    "Global Result Filter - OnResultExecuted");
            }
        }
            public void OnResultExecuting(ResultExecutingContext context)
            {
                var viewResult = context.Result as ViewResult;

                if (viewResult != null)
                {
                    var user = viewResult.ViewData.Model as User;

                    if (user != null)
                    {
                        user.Name += "**" + user.Name + "**";
                    }
                }
            }
 public override void OnResultExecuting(ResultExecutingContext context)
 {
     _logger.LogInformation("OnResultExecuting");
     base.OnResultExecuting(context);
 }
 public void OnResultExecuting(ResultExecutingContext context)
 {
     context.Result = Helpers.GetContentResult(context.Result, "Controller Override");
 }
 public override void OnResultExecuting(ResultExecutingContext context)
 {
     context.Result = Helpers.GetContentResult(context.Result, "Result filter");
 }
 public void OnResultExecuting(ResultExecutingContext context)
 {
     _timer = Stopwatch.StartNew();
 }
        public void FormatFilter_ContextContainsFormat_InRouteAndQueryData()
        {
            // If the format is present in both route and query data, the one in route data wins

            // Arrange  
            var mediaType = MediaTypeHeaderValue.Parse("application/json");
            var mockObjects = new MockObjects("json", FormatSource.RouteData);
            var httpContext = new Mock<HttpContext>();

            // Query contains xml    
            httpContext.Setup(c => c.Request.Query.ContainsKey("format")).Returns(true);
            httpContext.Setup(c => c.Request.Query.Get("format")).Returns("xml");

            // Routedata contains json
            var data = new RouteData();
            data.Values.Add("format", "json");

            var ac = new ActionContext(httpContext.Object, data, new ActionDescriptor());

            var resultExecutingContext = new ResultExecutingContext(
                ac,
                new IFilter[] { },
                new ObjectResult("Hello!"),
                controller: new object());

            var resourceExecutingContext = new ResourceExecutingContext(
                ac,
                new IFilter[] { });

            var filter = new FormatFilter(mockObjects.IOptions, mockObjects.ScopedInstance);

            // Act
            filter.OnResourceExecuting(resourceExecutingContext);
            filter.OnResultExecuting(resultExecutingContext);

            // Assert
            var objectResult = Assert.IsType<ObjectResult>(resultExecutingContext.Result);
            Assert.Equal(1, objectResult.ContentTypes.Count);
            AssertMediaTypesEqual(mediaType, objectResult.ContentTypes[0]);
        }
 public void OnResultExecuting(ResultExecutingContext context)
 {
     context.HttpContext.Response.Headers.Append("filters", "Controller Override - OnResultExecuting");
 }
 public override void OnResultExecuting(ResultExecutingContext context)
 {
     throw new InvalidProgramException("Result Filter threw.");
 }
 public override void OnResultExecuting(ResultExecutingContext context)
 {
     _logger.LogWarning("ClassFilter OnResultExecuting");
     base.OnResultExecuting(context);
 }