一般处理页面就是HttpHandler区域

-------------------------------封装类库

usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Web;usingSystem.Text.RegularExpressions;/****************************案例功能:*1,URL地址栏阻止(参数为aspx则跳转到错误页面)*2,Form表达阻止(表单的值为aspx则弹出错误)*3,阻止使用session***************************/namespaceHttpModuleDome{publicclassMyHttpModule:IHttpModule{#regionIHttpModule成员publicvoidDispose(){}publicvoidInit(HttpApplicationcontext){context.BeginRequest+=newEventHandler(context_BeginRequest);context.AcquireRequestState+=newEventHandler(context_AcquireRequestState);}//开始请求阶段voidcontext_BeginRequest(objectsender,EventArgse){HttpApplicationapplication=senderasHttpApplication;HttpContextcontext=application.Context;//Url地址栏阻止if(context.Request.QueryString.Count>0){for(inti=0;i<context.Request.QueryString.Count;i++){if(context.Request.QueryString[context.Request.QueryString.Keys[i]]=="aspx"){context.Response.Redirect("http://www.baidu.com");context.Response.End();}}}//Form表单阻止if(context.Request.Form.Count>0){for(inti=0;i<context.Request.Form.Count;i++){if(context.Request.Form[context.Request.Form.Keys[i]]=="aspx"){context.Response.Write("<script>alert('错误');location.href='"+context.Request.RawUrl+"'</script>");context.Response.End();}}}}//进入了HttpHandler区域,已经有了sessionvoidcontext_AcquireRequestState(objectsender,EventArgse){HttpApplicationapplication=senderasHttpApplication;//Global.asax的基类HttpContextcontext=application.Context;//封装了ASP.NET要处理的单次请求的所有信息if(context.Session.Count>0){//context.Response.End();//直接跳过AcquireRequestState之后的请求,结束请求}}#endregion}}

------------------------------------web.config里面引用

<system.web><httpModules><addname="MyhttpModule"type="HttpModuleDome.MyHttpModule,HttpModuleDome"/></httpModules></system.web>

------------------------------------也可以在Global.asax文件里面写

<%@ApplicationLanguage="C#"%><scriptrunat="server">/**格式:以Application_开头*///开始请求阶段voidApplication_BeginRequest(objectsender,EventArgse){//在应用程序启动时运行的代码}voidApplication_Start(objectsender,EventArgse){//在应用程序启动时运行的代码}voidApplication_End(objectsender,EventArgse){//在应用程序关闭时运行的代码}voidApplication_Error(objectsender,EventArgse){//在出现未处理的错误时运行的代码}voidSession_Start(objectsender,EventArgse){//在新会话启动时运行的代码}voidSession_End(objectsender,EventArgse){//在会话结束时运行的代码。//注意:只有在Web.config文件中的sessionstate模式设置为//InProc时,才会引发Session_End事件。如果会话模式设置为StateServer//或SQLServer,则不会引发该事件。}</script>