HTTP模块 - 将HTML内容或控件进行修改 [英] HttpModule - get HTML content or controls for modifications
问题描述
试过这样的事情:
HttpApplication的应用程序= S作为HttpApplication的; // s是OnBeginRequest事件
System.Web.UI.Page P =(System.Web.UI.Page)app.Context.Handler的发送者;
System.Web.UI.WebControls.Label LBL =新System.Web.UI.WebControls.Label();
lbl.Text =测试测试测试;
p.Controls.Add(LBL);
运行时,这个我得到未设置为一个对象的实例对象引用。最后一行...
我要如何插入特定loactions文本(asp.net/html)的两条线在原来的文件吗?我
和如何找出文件的扩展名(我只希望在ASPX文件...?
我不知道,但我不认为你可以使用一个HttpModule改变页面的控件树(请纠正我,如果我错了)。但是,您可以修改HTML标记,你就必须写有响应滤波器为此,有关示例,请参见 http://aspnetresources.com/articles/ HttpFilters.aspx ,或谷歌的HttpModule响应滤波器。
Tried something like this:
HttpApplication app = s as HttpApplication; //s is sender of the OnBeginRequest event
System.Web.UI.Page p = (System.Web.UI.Page)app.Context.Handler;
System.Web.UI.WebControls.Label lbl = new System.Web.UI.WebControls.Label();
lbl.Text = "TEST TEST TEST";
p.Controls.Add(lbl);
when running this I get "Object reference not set to an instance of an object." for the last line...
How do I get to insert two lines of text (asp.net/html) at specific loactions in the original file? And how do I figure out the extension of the file (I only want to apply this on aspx files...?
I'm not sure, but I don't think you can use an HttpModule to alter the Page's control tree (please correct me if I'm wrong). You CAN modify the HTML markup however, you'll have to write a "response filter" for this. For an example, see http://aspnetresources.com/articles/HttpFilters.aspx, or google for "httpmodule response filter".
这篇关于HTTP模块 - 将HTML内容或控件进行修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!