asp.net MVC ActionFilter 用于删除结果中的空行 [英] asp.net MVC ActionFilter for remove empty lines in result
问题描述
请帮我设置此操作过滤器.
Please help me with this action filter.
我想我需要使用 OnResultExecuted 方法
I think i need to use OnResultExecuted method
我如何才能访问 otput html 并替换其中的某些内容?
How can i have access to otput html and replace something in them?
谢谢.
推荐答案
如何使用去除空格的 HTTP 模块?实现简单、干净且可重用...
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. :-)
评论后编辑
这不适用于开箱即用的 .aspx 文件,因此您需要将 context_BeginRequest 更改为以下内容...
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);
}
}
这篇关于asp.net MVC ActionFilter 用于删除结果中的空行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!