httpmodule是如何工作的
当一个http请求到达httpmodule时,整个asp教程.net framework系统还并没有对这个http请求做任何处理,也就是说此时对于http请求来讲,httpmodule是一个http请求的“必经之路”,所以可以在这个http请求传递到真正的请求处理中心(httphandler)之前附加一些需要的信息在这个http请求信息之上,或者针对截获的这个http请求信息作一些额外的工作,或者在某些情况下干脆终止满足一些条件的http请求,从而可以起到一个filter过滤器的作用
using system;
using system.collections.generic;
using system.text;
using system.web;
namespace myhttpmodule
{
///
/// 说明:用来实现自己的httpmodule类。
///
public class myfirsthttpmodule : ihttpmodule
{
private void application_beginrequest(object sender, eventargs e)
{
httpapplication application = (httpapplication) sender;httpcontext context = application.context;
httprequest request = application.request;
httpresponse response = application.response;response.write("我来自自定义httpmodule中的beginrequest
");
}
private void application_endrequest(object sender, eventargs e)
{
httpapplication application = (httpapplication) sender;httpcontext context = application.context;
httprequest request = application.request;
httpresponse response = application.response;response.write("我来自自定义httpmodule中的endrequest
");
}#region ihttpmodule 成员
public void dispose()
{
}
public void init(httpapplication application)
{
application.beginrequest += new eventhandler(application_beginrequest);
application.endrequest += new eventhandler(application_endrequest);
}#endregion
}
}
httpmodule 的权限管理
////下面是web.config 里面的
///这样每执行个页面会调用这个方法。
.net代码
using system.configuration;
using system.linq;
using system.web;
using system.web.security;
using system.web.ui;
using system.web.ui.htmlcontrols;
using system.web.ui.webcontrols;
using system.web.ui.webcontrols.webparts;
using system.xml.linq;///
///class1 的摘要说明
namespace mymodule
{
public class mymodule : ihttpmodule
{
///
/// 初始化加入两个事件到application 里面去.
///
///
public void init(httpapplication application)
{
application.beginrequest += (new
eventhandler(this.application_beginrequest));
application.endrequest += (new
eventhandler(this.application_endrequest));
}
///在这里必须相当于是把response转过来。在这里根本直接用不了。不知道为啥。
///写这个的作用是进行权限判断。
private void application_beginrequest(object source, eventargs e)
{
httpapplication application = (httpapplication)source;
httpresponse responseo教程k = application.context.response;
responseok.write("beginning of request
");
}
private void application_endrequest(object source, eventargs e)
{
httpapplication application = (httpapplication)source;
httpresponse responseok = application.context.response;
responseok.write("end of request
");
}
public void dispose() { }
}
}
敢达决战官方正版 安卓版v6.7.9
下载敢达决战 安卓版v6.7.9
下载像素火影骨架佐助 (Perseverance Fire Shadow)手机版v1.16
下载要塞英雄 安卓版v33.20.0-39082670-Android
下载梦想城镇vivo最新版本 安卓版v12.0.1
梦想城镇vivo版是这款卡通风模拟经营类手游的渠道服版本,玩
怦然心动的瞬间 安卓版v1.0
怦然心动的瞬间是一款真人向的恋爱互动游戏,在游戏中玩家将扮演
曼尼汉堡店游戏 安卓版v1.0.3
曼尼汉堡店是一款非常好玩的精品恐怖类型冒险游戏,在这款游戏中
现代总统模拟器去广告版 安卓版v1.0.46
现代总统模拟器是一款休闲养成类游戏,可能对于不少的玩家来说都
现代总统模拟器付费完整版 安卓版v1.0.46
现代总统模拟器高级版在商店是需要付费的,相对于普通版本,高级