龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > asp.net编程 >

介绍Asp.net服务端状态管理是怎样实现的?(2)

时间:2009-12-21 11:47来源:未知 作者:admin 点击:
分享到:
上面的整个处理过程都是利用了Asp.net的对对象,这些对象的关系可以简单用下图表示: HttpHandler HttpHandler 是Asp.net的处理.aspx和.asmx的构架和方法.HttpHandler允

上面的整个处理过程都是利用了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对象的属性:

 

 

AllErrors

Gets an array of errors accumulated while processing an HTTP request.

 

Application

Gets the HttpApplicationState object for the current HTTP request.

 

ApplicationInstance

Gets or sets the HttpApplication object for the current HTTP request.

 

Cache

Gets the Cache object for the current application domain.

 

Current

Gets or sets the HttpContext object for the current HTTP request.

 

Error

Gets the first error (if any) accumulated during HTTP request processing.

 

Handler

Gets or sets the IHttpHandler object responsible for processing the HTTP request.

 

Items

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.

 

PreviousHandler

Gets the IHttpHandler object for the parent handler.

 

Profile

Gets the ProfileBase object for the current user profile.

 

服务端状态管理总结

    通常情况下,在开发服务器控件时,尽量少用服务端的状态管理,尤其是在能够使用客户端状态管理时,就不要用服务端状态管理。但在一些情况下,客户端浏览器被限制,比如cookies被禁止,这时使用服务端状态管理还是比较方便


精彩图集

赞助商链接