文章出處

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>
 

 


文章列表




Avast logo

Avast 防毒軟體已檢查此封電子郵件的病毒。
www.avast.com


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()