asp.net httpmodule 访问页面控件 备忘

时间:2024-07-28 17:04:44

用到的时候发现还得找代码,存一个例子方便自己和他人修改:

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq; namespace FirsteLite.OMS.HttpModule
{
public class CommonHttpModule : IHttpModule
{
#region IHttpModule 成员 public void Dispose()
{ } public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
} void context_PreRequestHandlerExecute(object sender, EventArgs e)
{
if (HttpContext.Current.Handler is Page)
{
Page page = (Page)HttpContext.Current.Handler;
page.PreRender += delegate(object ss, EventArgs ee)
{
//if (page is CDefault)
//{
// page.ClientScript.RegisterClientScriptInclude("key", page.ResolveUrl("~/myjs.js"));
//}
page.Header.Controls.AddAt(,new Literal {
Text = "<meta name=\"renderer\" content=\"webkit,ie-stand\" />" + Environment.NewLine +
"<meta http-equiv=\"X-UA-Compatible\" content=\"chrome=1,IE=8\" />" + Environment.NewLine
});
};
} } #endregion
}
}