介绍Asp.net服务端状态管理是怎样实现的?(2)
上面的整个处理过程都是利用了Asp.net的对对象,这些对象的关系可以简单用下图表示:
HttpHandler
HttpHandler是Asp.net的处理.aspx和.asmx的构架和方法.HttpHandler允许用户在应用程序处理单个的Url或者相同的扩展名.Asp.net里面有两个Build-in的HttpHandler,如下:
Handler |
描述 |
Asp.net Web Service |
默认用于处理.asmx的HttpHandler |
Asp.net 页面 |
默认用于处理.aspx的HttpHandler |
注意,上面的描述中用了默认,这意味这我们也可以写自己的处理.asmx或.aspx的HttpHandler实现
Asp.net的PageHandlerFactory是用来专门为创建用于被Developer操作的Page实例的,在这个实例中会包含我们常用的用户信息,比如Session,Application,ViewState等…….
通常情况下,HttpHandler可以是异步的,也可以使同步的。
同步的过程是指处理完整个Http请求才返回数据,而异步指处理完请求立刻返回数据.
Asp.net和服务端状态管理
Asp.net服务端状态管理是由我们最熟悉的Application和Session对象组成的,它们以集合的方式将用户信息储存在服务器.
Application是面向全局的,而Session对象是针对特定用户的.这两个对象都可以通过HttpContext对象来进行访问。
HttpContext对象
HttpContext提供了服务端状态管理并实现了HttpApplicationState和HttpSessionState,下面是一些HttpContext对象的属性:
|
Gets an array of errors accumulated while processing an HTTP request. |
|
|
Gets the HttpApplicationState object for the current HTTP request. |
|
|
Gets or sets the HttpApplication object for the current HTTP request. |
|
|
||
|
Gets or sets the HttpContext object for the current HTTP request. |
|
|
Gets the first error (if any) accumulated during HTTP request processing. |
|
|
Gets or sets the IHttpHandler object responsible for processing the HTTP request. |
|
|
Gets a key/value collection that can be used to organize and share data between an IHttpModule interface and an IHttpHandler interface during an HTTP request. |
|
|
||
|
服务端状态管理总结
通常情况下,在开发服务器控件时,尽量少用服务端的状态管理,尤其是在能够使用客户端状态管理时,就不要用服务端状态管理。但在一些情况下,客户端浏览器被限制,比如cookies被禁止,这时使用服务端状态管理还是比较方便
- 上一篇:C#泛型入门:详细学习C#中泛型使用
- 下一篇:C#实现动态生成Word文档