Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nathan Woulfe 421 posts 1578 karma points MVP 3x c-trib
    Dec 10, 2020 @ 08:46
    Nathan Woulfe
    0

    Route hijacking and response filtering

    Running into issues using an action filter on a hijacked route - annoyingly, it works in some cases but not in all...

    Normally looks like so:

    namespace Foo.Web.Controllers.RenderMvcControllers
    {
        public class FooBarController : DefaultController
        {
            [ReplaceSpecificMarkupFilter]
            public ActionResult FooBar(RenderModel renderModel)
            {
                var model = new FooBarViewModel(renderModel.Content);
                return CurrentTemplate(model);
            }
            [ReplaceSpecificMarkupFilter]
            public ActionResult AltFooBar(RenderModel renderModel)
            {
                var model = new AltFooBarViewModel(renderModel.Content);
                return CurrentTemplate(model);
            }
        }
    }
    

    Where the filter replaces some markup, the named actions allow different method per template name, and everything should work fine (and does, for some content types).

    When it fails, I get a super helpful error => "Filtering is not allowed"

    I'm at a loss as to why this works for some types and not others. The controller code runs fine, models are built and correct, but when execution hits the filter, it is null:

     public override void OnResultExecuted(ResultExecutedContext filterContext)
     {
         if ( filterContext.Exception != null)
         {
            return;
         }
         HttpResponseBase response = filterContext.HttpContext.Response;
         ReplaceSpecificMarkupFilter filter = _replaceSpecificMarkupFilterCtor();
    
         // response.Filter is sometimes null... It should not be.
         response.Filter = new StreamFilterBase(response.Filter, filter.Filter);
    }
    

    Any legends have any amazing solutions?

Please Sign in or register to post replies

Write your reply to:

Draft