操作HTTP响应 [英] Manipulating HTTP Response

查看:107
本文介绍了操作HTTP响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在的问题是密切相关的这一个,但远更具体。我们计划在这个问题中描述的目标的设计策略。

my current question is tightly related to this one, but is far more specific. We have to plan a design strategy for the objective described in that question.

我们希望通过这样做在ASP.NET Web窗体重写HTML 。我的问题是:它的策略是根据可行性 性能影响并在传统应用程序的实施工作

We want to do this by rewriting HTML on ASP.NET web forms. My question is: which strategy is the best according to parameters of feasibility, performance impact and implementation effort on legacy applications.

是基本上得到Web窗体的HTML输出,分析它,并根据用户定义的规则代替某些URL。在这个例子中,我会重写所有静态内容的CDN的URL,但它可以很容易地扩展到URL重写技术。我发现的地段(和我真正的意思的地段)的有关URL不必像 http://myblog.com/的URL重写角度篇PTED为 http://myblog.com/Default.aspx?post=2092 2092 间$ p $,却找不着我展示如何的巧妙的从内HTML格式正确旧式的URL缩短格式(所以页面将呈现直接短形式的URL)无深code干预。

is to basically get the HTML output of a Web Form, parse it, and replace certain URLs according to user-defined rules. In that example, I would rewrite all static content to CDN URLs, but it can be easily extended to URL rewriting techniques. I found lots (and I really mean lots) of articles about URL rewriting from the perspective of having URLs like http://myblog.com/2092 interpreted as http://myblog.com/Default.aspx?post=2092 but I found none showing me how to smartly format old-style URLs to shorter format right from inside HTML (so the page will render the short-form URL directly) [edit] without deep code intervention.

就像在上述问题的答案建议,编写截获HTML并重写它的一个HTTP模块。其实,我环顾四周,看到我可以设置执行HTML过滤一个 Response.Filter 流对象。

Like suggested in an answer of the above question, write an HTTP Module that intercepts the HTML and rewrites it. Actually, I looked around and saw I can set a Response.Filter stream object that performs the HTML filtering.


  • 赞成:我可以注入上的遗留应用的HTTP模块,配置重写通过XML规则,并有从CDN最古老的CRM /电子商务应用负载静态内容,而无需在所有 >。

  • 缺点:我怀疑(和注释<一个href=\"http://aspnetlibrary.com/articledetails.aspx?article=Use-Response.Filter-to-intercept-your-HTML\"相对=nofollow>这里印证了我的犯罪嫌疑人),具有重新实现方法,这在一般情况下的局部缓冲器工作,可能会导致不良的替代品。假设Write方法首先调用一大块像 TTP://mydomain.com/static/ima (其中我假设&LT; IMG SRC = H 已经被以前写),后来 ge.png/&GT; (所以你猜最后的网址:-P)与重写规则这正则表达式 http://mydomain.com/static/ [^] * http://cdn.com/path/$1 ,取代不这样做。要解决这一点,我可以用一个MemoryStream或类似的东西为缓存数据的完整集,然后进行换人,但它可能会引起麻烦在高负载的服务器

  • Pros: I can inject the HTTP Module on a legacy application, configure rewriting rules via XML and have the oldest CRM/ecommerce application load static content from a CDN without touching its code at all.
  • Cons: I suspected that (and a comment here confirms my suspects) having to reimplement a Stream's Write method, which operates on a partial buffer in the general case, can result in bad replacements. Suppose the Write method is first called with a chunk like ttp://mydomain.com/static/ima (where I assume <img src="h was already written before) and later ge.png" /> (so guess the final URL :-P) with a rewrite rule that regexes http://mydomain.com/static/[^"]* into http://cdn.com/path/$1, the substitution is not done. To workaround that, I could use a MemoryStream or something like that to buffer the complete set of data and then perform the substitutions, but it could cause troubles on highly loaded servers

重写渲染法的方式,如所描述的这里

Overriding Page's Render method in a way such as described here


  • 优点:不吃亏的分块问题

  • 缺点:需要定义一个基类的所有页面。可行的新的应用,不知道维持遗产应用程序。好像有,你不能直接实例HttpTextWriter问题

  • Pros: doesn't suffer the chunking problem
  • Cons: requires defining a base class for all pages. Feasible on new applications, not sure for maintaining legacy applications. Seems has a problem as you cannot instantiate HttpTextWriter directly

显然,对于新的web应用,我们将要开发的,我会采取策略2,但我真的很喜欢使用的动态组件很多,因为他们可以轻松地在应用程序需要他们被插入(所以,如果我们的新的应用程序将没有CDN要安装的功能是关闭的)。

Obviously, for the new webapps we'll have to develop, I would adopt strategy 2, but I really like using dynamic components a lot, as they can be plugged with ease when application requires them (so if our new app will be installed without a CDN the feature is turned off).

您将如何解决这两个战略'缺点(尤其是第一次)?而且,当然,你有其他的策略建议,以实现这一目标?

How would you fix both strategies' cons (particularly 1st)? And, of course, do you have other strategies to suggest to achieve this objective?

感谢您。

推荐答案

也许你可以使用ASP.NET的自适应控制的行为功能。参见自适应控件行为的建筑概述

Maybe you could use ASP.NET's "adaptive control behavior" feature. See Architectural Overview of Adaptive Control Behavior

基本上你将重新定义一个新的的HtmlTextWriter 类,它作为默认渲染联营,并覆盖A标记用自己的code渲染。

Basically you would redefine a new HtmlTextWriter class, associate it as the default renderer, and override "A" tag rendering with your own code.

这篇关于操作HTTP响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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