易截截图软件、单文件、免安装、纯绿色、仅160KB

ASP.Net中自定义Http处理及应用之HttpModule篇

HttpHandler实现了类似于ISAPI Extention的功能,他处理请求(Request)的信息和发送响应(Response)。HttpHandler功能的实现通过实现IHttpHandler接口来达到。而HttpModule实现了类似于ISAPI Filter的功能。
HttpModule的实现
HttpModules实现了类似于ISAPI Filter的功能,在开发上,通常需要经过以下步骤:
编写一个类,实现IhttpModule接口
实现Init 方法,并且注册需要的方法
实现注册的方法
实现Dispose方法,如果需要手工为类做一些清除工作,可以添加Dispose方法的实现,但这不是必需的,通常可以不为Dispose方法添加任何代码。
在Web.config文件中,注册您编写的类
下面是一个HttpModules的示例,在这个示例中,只是简单的注册了HttpApplication 的BeginRequest 和 EndRequest事件,并且通过这些事件的实现方法,将相关的信息打印出来。
例1:
  using System;
using System.Web;
namespace MyModule{
public class MyModule : IHttpModule {
public void Init(HttpApplication application) {
application.BeginRequest += (new
EventHandler(this.Application_BeginRequest));
application.EndRequest += (new
EventHandler(this.Application_EndRequest));
}
private void Application_BeginRequest(Object source, EventArgs e) {
HttpApplication Application = (HttpApplication)source;
HttpResponse Response=Application.Context.Response;
Response.Write("<h1>Beginning of Request</h1><hr>");
}
private void Application_EndRequest(Object source, EventArgs e)
{
HttpApplication application = (HttpApplication)source;
HttpResponse Response=Application.Context.Response;
Response.Write("<h1>End of Request</h1><hr>");
}
public void Dispose() { }
}
}
程序的开始引用了如下名称空间:
using System;
using System.Web;
因为HttpApplication、HttpContext、HttpResponse等类在System.Web中定义,因此,System.Web名称空间是必须引用的。
MyModule类实现了IhttpModule接口。在Init方法中,指明了实现BeginRequest 和EndRequest 事件的方法。在这两个方法中,只是简单的分别打印了一些信息。
下面,在Web.config文件中注册这个类,就可以使用这个HttpModule了,注册的方法如下:
<configuration>
<system.web>


相关文档:

Asp.Net常用的三十三种代码

1. 打开新的窗口并传送参数:
  传送参数:
response.write("<script>window.open(’*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"’)</script>")
  接收参数:
string a = Request.QueryString("id");
string b = Request.QueryString("id1");
  2.为按钮添加对话框
Button1 ......

asp.net 设置出错页

    <system.web> 
      <!--********出错页的设定********-->
    <customErrors mode="On" defaultRedirect="~/Error.htm"> </customErrors> ......

如何使用ASP.NET Profile


Asp.Net中有一套与用户相关联的属性设置,可以通过在WebConfig里配置来直接使用,他的作用为
存储和使用唯一与用户对应的信息
展现个人化版本的Web应用程序
用户的唯一身份标识在再次访问时识别用户
Asp.Net Profile提供的跟用户相关的类型都是强类型
首先生成数据库脚本,使用Visual Studio 2005 命令提示,输入 ......

ASP.NET 2.0中实现模板中的数据绑定

模板化的数据绑定控件为我们在页面上显示数据提供了根本的灵活性。你可能还记得ASP.NET v1.x中的几个模板化控件(例如DataList和Repeater控件)。ASP.NET 2.0仍然支持这些控件,但在模板中绑定数据的语法已经被简化和改善了。本文将讨论在数据绑定控件模板中绑定数据的多种方法。
数据绑定表达式
ASP.NET 2.0改善了模板中 ......

ASP.NET Mischellous

@Register : Register a user control or class with alias to this page.
@Import: Import a namespace.
@Reference: Link user controls or other page to complile current page. 支持数据跨页面的传送
页面事件:PreInit(创建服务器控件), Init(初始化服务器控件的状态), InitComplete,PreLoad, Load, Lo ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号