Page 236 - DCAP408_WEB_PROGRAMMING
P. 236

Web Programming




                    Notes          <%
                                   dim  i
                                   For  Each  i  in  Application.StaticObjects
                                       Response.Write(i  &  “<br  />”)
                                   Next
                                   %>



                                     Did u know?  What is Staicobject collection?
                                     The StaticObjects collection contains all of the objects created by using the <OBJECT> tags
                                     within the scope of the Application object. You can use the collection to determine the
                                     value of a specific property for an object or to iterate through the collection and retrieve
                                     all properties for all static objects.
                                   Lock and Unlock


                                   You can lock an application with the “Lock” method. When an application is locked, the users
                                   cannot change the Application variables  (other than  the one currently accessing it). You can
                                   unlock an application with the  “Unlock”  method. This  method removes  the lock from  the
                                   Application variable:
                                   <%
                                   Application.Lock
                                       ‘do  some  application  object  operations
                                   Application.Unlock
                                   %>



                                     Did u know?  What is lock and unlock method?

                                     The Lock  method  blocks  other  clients  from  modifying  the variables  stored  in  the
                                     Application object, ensuring that only one client at a time can alter or access the Application
                                     variables. If you do not call the Application.Unlock method explicitly, the server unlocks
                                     the locked Application object when the .asp file ends or times out.

                                   Pitfalls of Application Variables

                                   Because only one  instance of  the Application object  exists  for the  entire Web application,
                                   application variables can be used more liberally than session variables. However, the Application
                                   object does take up memory on the Web server, so only items that need to be stored in application
                                   scope should be entered into the Application object. Two common pitfalls should be avoided
                                   when working with application variables:
                                      Pitfall 1 - Do not put objects into the Application object unless vitally needed.

                                      Pitfall 2 - Only create application variables that are necessary.  Why create  unneeded
                                       application variables when they’ll only waste your Web server’s memory?
                                   A common pitfall among developers is wanting to place objects in the Application. One object
                                   that is particularly alluring to put into the Application is the ADO Connection object, which is
                                   used to connect to a database. We’ll discuss this object in detail during Week 3. It may seem like



          230                               LOVELY PROFESSIONAL UNIVERSITY
   231   232   233   234   235   236   237   238   239   240   241