3

I am trying to modify the output stream to search/replace some XHTML tags returned from a View. I could use an traditional ASP.NET response filter, but thought to try the ASP.NET MVC action filter first.

public class MyResultFilter : ActionFilterAttribute
{
    public override void OnResultExecuting(ResultExecutingContext filterContext)
    {            
        base.OnResultExecuting(filterContext);
    }
    public override void OnResultExecuted(ResultExecutedContext filterContext)
    {
        ViewResult viewResult = filterContext.Result as ViewResult;
        Debug.WriteLine("OnResultExecuted");
        base.OnResultExecuted(filterContext);
    }   
}

I'm having trouble determining how to modify or get ahold of the viewResult output stream. Examples on the web only show logging basic properties, never modifying the result.

1 Answer 1

3

I don't think it's good idea to do this with ActionFilterAttribute, as soon at it is dedicated for controller level decisions, not thinks specific to the HTML request post-processing. The best way to do this properly is possibly to create specific base View class or even ViewEngine, or use old good HttpModules as they were created for things like you are trying to do. Cheers.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.