如何从 HttpModule 中检索响应 html?
这是我特别想做的事情:
我编写了一个 HttpModule 来执行一些特定于站点的跟踪。我们网站上的一些旧 .aspx 页面是硬编码的,没有真正的控件,但它们是 .aspx 文件,因此我的模块在被请求时仍然运行。
我的模块的处理程序附加到 PostRequestHandlerExecute,因此我相信将发送回请求者的内容应该已经确定。
我需要能够提取标题标签中的任何字符串。
因此,if
<title>Chunky Bacon</title>
在最终渲染的 HTML 中发送给请求者。然后我想要“厚块培根”。
有想法吗?
Here is what I'm specifically trying to do:
I have written a HttpModule to do some site specific tracking. Some old .aspx pages on our site are hard coded with no real controls, but they are .aspx files so my module still runs when they are requested.
My module's handler is attached to the PostRequestHandlerExecute, so I believe what will be sent back to the requester should have already been determined.
I need to be able to extract whatever string is in the title tag.
So if
<title>Chunky Bacon</title>
is sent to the requester in the final rendered HTML. Then I want "Chunky Bacon".
Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有趣的小挑战。
代码如下:
StreamWatcher.cs
TitleModule.cs
Fun little challenge.
Here's the code:
StreamWatcher.cs
TitleModule.cs
4GuysFromRolla 上有一篇文章讨论了创建 HttpResponse 过滤器,这些过滤器基本上是在将响应传递到最终输出流(拦截器)之前处理响应的流。
https://web. archive.org/web/20210510022033/https://aspnet.4guysfromrolla.com/articles/120308-1.aspx
There is an article on 4GuysFromRolla that talks about creating HttpResponse filters which are basically streams that process the response before passing it through to the final output stream (an interceptor).
https://web.archive.org/web/20210510022033/https://aspnet.4guysfromrolla.com/articles/120308-1.aspx