ASP.NET对矫正一个网页的HTML之前被发送到客户端 [英] ASP.NET modifing the HTML of a page before it is sent to the client

查看:107
本文介绍了ASP.NET对矫正一个网页的HTML之前被发送到客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要赶着ASP.NET的HTML之前被发送到客户端,以便做就可以了最后一分钟的字符串操作,然后发送修改后的版本到客户端了。

I need to catch the HTML of a ASP.NET just before it is being sent to the client in order to do last minute string manipulations on it, and then send the modified version to the client.

例如

在页面加载
每一个控制已经正确呈现
页面的完整HTML已经准备好要传输回客户端

The Page is loaded Every control has been rendered correctly The Full html of the page is ready to be transfered back to the client

有没有一种办法,在ASP.NET

Is there a way to that in ASP.NET

推荐答案

您可以重写页面的Render方法。然后调用基实现并提供您的HtmlTextWriter对象。下面是一个例子。

You can override the Render method of your page. Then call the base implementation and supply your HtmlTextWriter object. Here is an example

protected override void Render(HtmlTextWriter writer)
{
    StringWriter output = new StringWriter();
    base.Render(new HtmlTextWriter(output));
    //This is the rendered HTML of your page. Feel free to manipulate it.
    string outputAsString = output.ToString();

    writer.Write(outputAsString);
}

这篇关于ASP.NET对矫正一个网页的HTML之前被发送到客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆