您的位置:首页 > 其它

自定义处理页面请求

2005-04-21 03:02 369 查看
主要是继承IHttpModule和IHttpHandler来重写其 中的方法,IhttpModule 中重写其Init方法及各种请示过程事件和Dispose方法

using System.Web;
using System;

namespace CustomerHttpModules

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

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

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

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

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

同样地建个类库

using System;
using System.Web;

namespace CustomerHttpHandler

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

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

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

看看效果吧
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐