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