自定义处理页面请求

       主要是继承IHttpModule和IHttpHandler来重写其 中的方法,IhttpModule 中重写其Init方法及各种请示过程事件和Dispose方法

using  System.Web;
using  System;

namespace  CustomerHttpModules
{
    
/// <summary>
    
/// Class1 的摘要说明。
    
/// </summary>

    public class MyHttpModules:IHttpModule
    
{
        
public MyHttpModules()
        
{
             
        }

        
IHttpModule 成员
    }

}

 

然后生成dll,新建个asp.net应用,引用此dll,在web.config中加入

<httpModules>
  <add name="test" type="CustomerHttpModules.MyHttpModules,CustomerHttpModules"/>
 </httpModules>

则当有页面请求时会查找到此dll,然后执行其中过程。

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

以下为重写IHttpHandler中方法的代码:

同样地建个类库

using  System;
using  System.Web;

namespace  CustomerHttpHandler
{
    
/// <summary>
    
/// Class1 的摘要说明。
    
/// </summary>

    public class TestCustomerHttpHandler:IHttpHandler
    
{
        
public TestCustomerHttpHandler()
        
{
            
//
            
// TODO: 在此处添加构造函数逻辑
            
//
        }

        
IHttpHandler 成员
    }

}

 

所有页面请示的核心处理都是通过IHttpHandler的ProcessRequest方法来完成,因此只要我们重写此方法,则无论页面有任何请求,都会被我们所重写的内容代替掉。嘿嘿

生成dll后再在asp.net应用中的 web.config 中加入

<httpHandlers>
  <add verb="*" path="*" type="CustomerHttpModules.MyHttpModules,CustomerHttpModules"/>
 </httpHandlers>

看看效果吧

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值