在MVC3中更改HTML输出

fre*_*rik 3 asp.net-mvc razor

在我的MVC3应用程序中,当用户使用IE <9时,我想删除输出的所有HTML5标签,以避免使用前端解决方法.

我看了中使用HttpModule,ActionFilter中,OnResultExecuted控制器上的内部和方法Application_Start.

到目前为止,我已经想到我需要使用以下内容将输出作为字符串 HttpApplication.Context.Response.OutputStream:

HttpApplication application = (HttpApplication)source;
HttpResponse response = application.Context.Response;
StreamReader sr = new StreamReader(stream);
string content = sr.ReadToEnd();
Run Code Online (Sandbox Code Playgroud)

但我得到的只是同样的错误Stream was not readable.我可以写回复context.Response.Write.

从阅读SO和谷歌,MVC似乎没有相同的"页面生命周期"有webforms(我只是覆盖Render,它工作正常),这使得sens.

所以我的问题是如何在MVC中将HTML作为字符串获取?有没有人试图操纵HTML输出?

Dan*_*plo 7

我认为你应该可以使用ActionFilter来做到这一点.我在这篇博客文章中看到过有人修改输出流的例子.或者在这篇文章中.