文章出處
文章列表
1.HttpModule可用在asp.net 管線事件觸發的過程中。。 可處理一些通用的操作,如給特定請求加 gzip壓縮。
2.示例代碼:
using System; using System.Web; namespace MyWebApp { public class MyHttpModule : IHttpModule { public void Init(HttpApplication application) { application.BeginRequest += new EventHandler(application_BeginRequest); } public void application_BeginRequest(object sender, EventArgs e) { HttpContext context = (sender as HttpApplication).Context; context.Response.Write("這一部分是由HttpModule添加!<br><script>alert('測試腳本標簽')</script>"); } #region IHttpModule 成員 void IHttpModule.Dispose() { throw new NotImplementedException(); } #endregion } }
3.要使 HttpModule生效。還需要配置web.config。
<system.webServer>
<modules> <remove name="MyHttpModule"/> <add name="MyHttpModule" type="MyWebApp.MyHttpModule"/> </modules>
</system.webServer>
文章列表
全站熱搜