Search code examples
model-view-controlleraction-filter

asp.net MVC ActionFilter for remove empty lines in result


Please help me with this action filter.

I think i need to use OnResultExecuted method

How can i have access to otput html and replace something in them?

thank you.


Solution

  • How about using a whitespace removal HTTP module? It's simple to implement, clean and reusable...

    http://madskristensen.net/post/A-whitespace-removal-HTTP-module-for-ASPNET-20.aspx

    As with any generic whitespace removal solution though, it can easily introduce errors by removing white space where it is required. It wouldn't take long to give it a try though. :-)

    Edited after comments

    This will not work with .aspx files out of the box so you'll need to change the context_BeginRequest to the following...

    void context_BeginRequest(object sender, EventArgs e)
    {
        HttpApplication app = sender as HttpApplication;
        if (app.Response.ContentType == "text/html"
            || app.Response.ContentType == "application/xhtml+xml")
        {
            app.Response.Filter = new WhitespaceFilter(app.Response.Filter);
        }
    }