ASP.NET 保存发送到浏览器的 HTML

发布于 2024-07-19 05:30:18 字数 111 浏览 9 评论 0原文

我需要保存发送到浏览器的完整且准确的 HTML 以进行某些交易(出于合法跟踪目的)。我怀疑我不确定是否有合适的挂钩来执行此操作。 有人知道吗? (顺便说一句,我知道还需要保存相关页面,例如样式表和图像。)

I need to save the full and exact HTML sent to the browser for some transactions (for legal tracking purposes.) I suspect I am not sure if there is a suitable hook to do this. Does anyone know? (BTW, I am aware of the need to also save associated pages like style sheets and images.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

我ぃ本無心為│何有愛 2024-07-26 05:30:18

您可以创建一个 http 模块 并将输出流保存在某处。

您应该挂钩 PreSendRequestContent 事件...:

此事件在 ASP.NET 将响应内容发送到客户端之前引发。 此事件允许我们在将内容交付给客户端之前更改内容。 我们可以使用此事件将所有页面中常见的内容添加到页面输出中。 例如,常见的菜单、页眉或页脚。

You can create an http module and have the output stream saved somewhere.

You should hook to PreSendRequestContent event...:

This event is raised just before ASP.NET sends the response contents to the client. This event allows us to change the contents before it gets delivered to the client. We can use this event to add the contents, which are common in all pages, to the page output. For example, a common menu, header or footer.

痞味浪人 2024-07-26 05:30:18

您可以附加到 PreSendRequestContent。 此事件在内容发送之前引发,让您有机会修改它,或者根据您的情况保存它。

有关拦截模式的 P&P 文章

You could attach to the PreSendRequestContent. This event is raised right before the content is sent and gives you a chance to modify it, or in your case, save it.

P&P article on interception pattern

陌路黄昏 2024-07-26 05:30:18

您可以实现一个响应过滤器。 这是一个很好的示例,它处理 ASP.NET 生成的 HTML。 除了将 HTML 发送到客户端之外,您还应该能够将 HTML 写入数据库或其他合适的存储。

这是将过滤器挂接到应用程序中的另一种更简单的方法:

在 Global.asax 中,将以下代码放入 Application_BeginRequest 处理程序中:

void Application_BeginRequest(object sender, EventArgs e)
{
    Response.Filter = new HtmlSavingFilter(Response.Filter);
}

You could implement a response filter. Here is a nice sample that processes the HTML produced by ASP.NET. In addition to the HTML being sent to the client you should be able to also write the HTML to a database or other suitable storage.

Here is an alternate and IMO much easier way to hook the filter into your application:

in Global.asax, place the following code in the Application_BeginRequest handler:

void Application_BeginRequest(object sender, EventArgs e)
{
    Response.Filter = new HtmlSavingFilter(Response.Filter);
}
柒七 2024-07-26 05:30:18

我想您只想保存某些页面的渲染 html。 如果是这样,我一直在我的一个应用程序中使用以下方法,将渲染的 html 存储在磁盘上的某个位置以进行缓存。 该方法只是覆盖页面的渲染事件。

protected override void Render(HtmlTextWriter writer)
{
    using (HtmlTextWriter htmlwriter = new HtmlTextWriter(new System.IO.StringWriter()))
    {
        base.Render(htmlwriter);
        string html = htmlwriter.InnerWriter.ToString();


        using (FileStream outputStream = new FileStream(@"C:\\temp.html", FileMode.OpenOrCreate))
        {
             outputStream.Write(html, 0, html.Length);
             outputStream.Close();
        }

        writer.Write(html);
    }
}

真的很适合我。

I suppose you only want to save the rendered html for certain pages. If so, I have been using the following approach in one of my applications that stores the rendered html for caching purpose somewhere on the disk. This method simply overrides the render event of the page.

protected override void Render(HtmlTextWriter writer)
{
    using (HtmlTextWriter htmlwriter = new HtmlTextWriter(new System.IO.StringWriter()))
    {
        base.Render(htmlwriter);
        string html = htmlwriter.InnerWriter.ToString();


        using (FileStream outputStream = new FileStream(@"C:\\temp.html", FileMode.OpenOrCreate))
        {
             outputStream.Write(html, 0, html.Length);
             outputStream.Close();
        }

        writer.Write(html);
    }
}

Really works well for me.

孤单情人 2024-07-26 05:30:18

还有专门为此目的制作的硬件设备。 我们使用了一个名为“PageVault”的工具。

There are also hardware devices made specifically for this purpose. We've used one called "PageVault".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文