您好,欢迎光临本网站![请登录][注册会员]  
文件名称: ASP编程完全手册ASP编程完全手册
  所属分类: C#
  开发工具:
  文件大小: 561kb
  下载次数: 0
  上传时间: 2011-02-09
  提 供 者: sure*****
 详细说明: Application Object You can use the Application object to share information among all users of a given application. An ASP-based application is defined as all the .asp files in a virtual directory and its subdirectories. Because the Application object can be shared by more than one user, there are Lock and Unlock methods to ensure that multiple users do not try to alter a property simultaneously. Syntax Application.method Collections Contents Contains all of the items that have been added to the Application through script com mands. StaticObjects Contains all of the objects added to the session with the tag. Methods Lock The Lock method prevents other clients from modifying Application object properties. Unlock The Unlock method allows other clients to modify Application object properties. Events Application_OnEnd Application_OnStart Scripts for the preceding events are declared in the global.asa file. For more information about these events and the global.asa file, see the Global.asa Reference. Remarks You can store values in the Application Collections. Information stored in the Application collections is available throughout the application and has application scope. The following script demonstrates storage of two types of variables. <% Application("greeting") = "Welcome to My Web World!" Application("num") = 25 %> Each of these variables would be members of the Application Contents Collection. You can also assign a component instance to a variable that has application scope. If you assign a component instance to a variable with the Server.CreateObject method, the variable will be a member of the Application.Contents collection. If the variable is assigned with the tag, the variable will be a member of the Application StaticObjects Collection. You should be careful about assigning component instances to variables with application scope., as some components are not designed to be given application scope. For more information, seeDetermining Component Scope in the Creating Components for ASP section of the Programmer's Reference. If you assign a component instance to a variable in the Application Contents Collection, and use Visual Basic® Scripting Edition as your primary scripting language, you must use the Set keyword. This is illustrated in the following script. <% Set Application("Obj1") = Server.CreateObject("MyComponent") %> You can then reference the methods and properties of MyComponent on subsequent Web pages by using this script <% Application("Obj1").MyObjMethod %> or by extracting a local copy of the object and using the following <% Set MyLocalObj1 = Application("Obj1") MyLocalObj1.MyObjMethod %> Another way to create objects with application scope is by using the tag in the global.asa file. For more information, see the Global.asa Reference. You cannot store a built-in object in the Application object. For example, each of the following lines returns an error. <% Set Application("var1") = Session Set Application("var2") = Request Set Application("var3") = Response Set Application("var4") = Server Set Application("var5") = Application Set Application("var6") = ObjectContext %> You should be aware of the threading model used by any components you give application scope. The threading model used to develop the component will have a significant impact on whether a component instance should be assigned to a variable in one of the Application collections. For more information, seeComponent Design Guidelines. If you store an array in a Application object, you should not attempt to alter the elements of the stored array directly. For example, the following script does not work <% Application("StoredArray")(3) = "new value" %> This is because the Application object is implemented as a collection. The array element StoredArray(3) does not receive the new value. Instead, the value would be included in the Application object collection, and would overwrite any information that had previously been stored at that location. It is strongly recommended that if you store an array in the Application object, you retrieve a copy of the array before retrieving or changing any of the elements of the array. When you are done with the array, you should store the array in the Application object all over again, so that any changes you made are saved. This is demonstrated in the following scripts. ---file1.asp--- <% 'Creating and initializing the array dim MyArray() Redim MyArray(5) MyArray(0) = "hello" MyArray(1) = "some other string" 'Storing the array in the Application object Application.Lock Application("StoredArray") = MyArray Application.Unlock Response.Redirect("file2.asp") %> ---file2.asp--- <% 'Retrieving the array from the Application Object 'and modifying its second element LocalArray = Application("StoredArray") LocalArray(1) = " there" 'printing out the string "hello there" Response.Write(LocalArray(0)&LocalArray(1)) 'Re-storing the array in the Application object 'This overwrites the values in StoredArray with the new values Application.Lock Application("StoredArray") = LocalArray Application.Unlock %> Example The following example uses the application variable NumVisits to store the number of times that a particular page has been accessed. The Lock method is called to ensure that only the current client can access or alter NumVisits. Calling the Unlock method then enables other users to access the Application object. <% Application.Lock Application("NumVisits") = Application("NumVisits") + 1 Application.Unlock %> This application page has been visited <%= Application("NumVisits") %> times! ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: ASP编程完全手册
 输入关键字,在本站1000多万海量源码库中尽情搜索: