ASP.NET 保存发送到浏览器的 HTML
我需要保存发送到浏览器的完整且准确的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以创建一个 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.
您可以附加到 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
您可以实现一个响应过滤器。 这是一个很好的示例,它处理 ASP.NET 生成的 HTML。 除了将 HTML 发送到客户端之外,您还应该能够将 HTML 写入数据库或其他合适的存储。
这是将过滤器挂接到应用程序中的另一种更简单的方法:
在 Global.asax 中,将以下代码放入 Application_BeginRequest 处理程序中:
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:
我想您只想保存某些页面的渲染 html。 如果是这样,我一直在我的一个应用程序中使用以下方法,将渲染的 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.
Really works well for me.
还有专门为此目的制作的硬件设备。 我们使用了一个名为“PageVault”的工具。
There are also hardware devices made specifically for this purpose. We've used one called "PageVault".