tags:

views:

1041

answers:

1

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.

+3  A: 

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.

dimarzionist