本文實例講述了C#使用IHttpModule接口修改http輸出的方法。分享給大家供大家參考。具體實現方法如下:
using System;using System.Collections.Generic;using System.Linq;using System.Web;//修改http輸出先建個類這個類作為模塊mould就要實現接口namespace 修改_HTTP_輸出{ public class MyMould:IHttpModule //實現接口 { //點擊實現接口就會出來以下對應的屬性和一個方法 public void Dispose() //處理屬性 { throw new NotImplementedException(); } HttpContext c = null; //定義個下面要用的當前請求對象變量初值為null public void Init(HttpApplication context) //初始化方法,HttpApplication是應用程序類 { this.c = context.Context; //1:給當前請求c賦值,Context獲取當前請求的Http特定信息 context.BeginRequest += new EventHandler(context_BeginRequest); //當應用開始請求時;2:beginRequest是一個事件用委托定義事件 } void context_BeginRequest(object sender, EventArgs e) //事件的處理方法 { c.Response.Write("你的請求被我在mould中改了"); } //上面的事件響應需要注冊測在web.config }}
希望本文所述對大家的C#程序設計有所幫助。
新聞熱點
疑難解答