Tutorials to .com

Tutorials to .com » Asp » Base » Advanced Programming ASP 3.0 (17)

Advanced Programming ASP 3.0 (17)

Print View , by: iSee ,Total views: 13 ,Word Count: 3095 ,Date: Sun, 26 Apr 2009 Time: 1:48 AM

Chapter 5 Script run-time library object
The previous section has introduced the use of asp on the server instance of the definition of the object, make full use of available methods and properties to expand the performance of ASP. The availability of a series of targets, including targets and standards script IIS / ASP components installed, as well as create your own or from other suppliers to purchase the object. Can also be a variety of sites on the Internet free of charge to download the object, and use their own page.
This chapter will discuss ASP scripting environment from the generally known as "script run-time library" (Scripting Runtime Library) of the object. These objects through the use of the scripting engine is available to the code, and the ASP script with a variety of practical tasks completed.
There is also a component of "the activities of server components" (Active Server Component), through a separate ActiveX DLL files or other documents to achieve. Behind the relevant chapters will be discussed.
Of course, the need to study how to use these objects on the page. In the previous chapter, we already know how to provide the server a way to instantiate objects, this chapter will discuss the content in depth.
This chapter will introduce the following:
Scripting engine to provide a script of what the object.
How do I create a script object, and examples of other components.
Script objects and attributes of the members of outline.
How to use the script in the code object.
Began to study the following definition of the object script.

5.1 Scripting Object definition
The previous section examined the ASP object model.
Object model is used to understand the system, the relationship between the various parts of one of the basic means.
ASP Object Model provides a structure, used to manipulate as a whole HTTP request, and ASP in response to different elements in the environment. For example, we have already seen how the ASP request object by looking at the cookie set by the browser from any cookie value.
We use the scripting language is also object model. However, the scripting language provided by the object model is different from the ASP DLL directly from the object model, the script is by the Microsoft Scripting Runtime library (scrrun.dll) provided by the Active Scripting to install the default scripting engine, also installed the Microsoft Script run-time library.

5.1.1 different types of objects and components
Not to "target" and "components" of these two terms are confused, in a certain range they can be used as part of ASP, the same can be visited through COM. Conceptually they can be divided into four categories:
ASP built-in objects, such as ObjectContext, Request, Response, Application, Session, Server and ASPError. This book in Chapter 2 to Chapter 4 of these elements has been studied.
Scripting object. Run-time library, through the use of scripts, such as Dictionary, FileSystem and TextStream. This is the subject of this chapter to be discussed.
Components can be installed. By Microsoft in IIS 5.0 and ASP 3.0 installed to provide standards. This will be discussed in the next chapter.
Other components. Purchased from other independent companies, and found on the website or create your own components. There are a number of other services or products from Windows to provide the components, such as Windows Scripting Host. In the book's appendix provides a list of some of the specialized sections of the book describes how to build their own components.

5.1.2 vbscript and jscript scripting object
Script run-time library as a part, Microsoft offers three main target:
Dictionary object to provide a very useful storage object, it is used to store value, through the object's name rather than their index visit and quote. For example, for storage from the ASP Request object to retrieve the name / value pairs, which is very appropriate.
FileSystemObject object server provides access to the underlying file system (on the client to use IE 5.0, and called "Hypertext application (HTA)" page of the special type of collaborative use). FileSystemObject object traversal can be used for local and network computer drives, folders and documents.
TextStream provide for storage on disk files for use with the FileSystemObject object collaboration. TextStream object can read or write text (sequence) file, and only through the FileSystemObject object to instantiate, so people often think that TextStream is a subset of the target object FileSystemObject.
A host of other FileSystemObject object is used to interact with the file system object and set the "parent." The objects provide a set of three: Drives, Folders and Files collections, each collection are the Drive, Folder and File objects collection. They are used for disk drives, folders (directories) and files traverse and positioning. The relationship between objects as shown in Figure 5-1:

Figure 5-1 Script run-time library, the relationship between objects
Below will be followed by these objects and collections, as well as how to use them. However, we must first understand the object instance with the component to create or instantiate the difference between means. This is the main contents of the next section.

5.2 Health and components to create the object instance
Script run-time library to create the instance of the object and create objects and components of any other examples of exactly the same way. Can be used to provide the ASP Server Object CreateObject method (to ensure that the target page created in the current environment), or use a <OBJECT> elements. We will examine these two methods, what kind of method used depends on the needs of the page.

5.2.1 use the Server.CreateObject method
Server object in the study as the time to see examples of components or other objects can be the basis of their ProgID to create:
Dim objThis
Set objThis = Server.CreateObject ( "ADODB.Connection")
ProgID string "official" format is the "provider. Components. Version", the supplier's name and version is optional. ProgID usually contains only the first two parts (as cases). ProgID a small number of suppliers to set up the version number, which will avoid the backward compatibility of the new version using the same ProgID, which requires changing the ASP page to use the new version.

5.2.2 use elements <OBJECT>
Can use standard HTML <OBJECT> elements RUNAT parameters and by increasing the value specified for the "SERVER" to the server to create a component instance. In addition, often the object is to provide the ProgID string rather than the number of ClassID:
<OBJECT ID="objThis" RUNAT="SERVER" PROGID="This.Object">
<PARAM NAME="param1" VALUE="value1">
<PARAM NAME="param2" VALUE="value2">
If the script above, the object of a corresponding attribute in the script used in <OBJECT> element element can be set through <PARAM>, as is usually done in the HTML page the same. Used in the ASP does not require <OBJECT> element CODEBASE attribute, when it is unavailable, the server will not attempt to download and install the object or component.
1. Specify a ClassID
In addition, you can specify you want to create the object or component ClassID. In do not know what the target machine to install other components, this is very useful. For example, the client on the browser page component instantiation.
In theory, component ProgID (text "suppliers. Component") should not conflict with each other, should be unique. However, it is not perfect. The possibility of a North American supplier and a Greek island of the same name suppliers. However, when using the ClassID to identify, because the only ClassID, the same name, the situation would not have happened.
If you decide to use an object or component ClassID, should be put CLASSID attributes, rather than PROGID attributes. Such as:
CLASSID = "clsid: 892D6DA7-E0F9-11D2-B2E9-00105A42AF30">
<PARAM NAME="param1" VALUE="value1">
<PARAM NAME="param2" VALUE="value2">
However, in its own instance of the server object, should be aware of objects and components installed. This code in ASP to create object instance, you can safely use the ProgID. This is the ASP page in the ClassID few of the reasons for use. However, because the ProgID for finding ClassID, if desired components can also be used in place of or ClassID the object ProgID.
2. Set up the scope object instance
By default, all ASP pages to create instances of objects and components (whether to use Server.CreateObject method or <OBJECT> elements) are within the scope of the page (page scope). This means that objects and components only in the ASP page to run when there is, when completed and the results page is sent to the client after automatically canceled.
However, if the global.asa file (which exist in the site or virtual application's root directory) <OBJECT> placing a statement object or component can be designated as the application scope or session scope.
(1) scope in the application layer to create the object
SCOPE attribute by setting the "APPLICATION", create an application layer object scope:
<OBJECT ID = "objThis" RUNAT = "SERVER" PROGID = "This.Object"
Applications to create the beginning of the object instance, that is, once the user from the virtual directory of the application requests a page, on the creation of object instance. For the default Web site, which can be any site on the directory. Applications until the end (the end of the last user session) before the object instance has been, and applications can be a virtual directory or site within any page of the introduction and use of any user.
(2) in the session layer to create the object scope
If you want to create users from a single object instance, the scope for him to visit all the pages can be created session scope object layer. This property is set by SCOPE for the "SESSION" to achieve:
<OBJECT ID = "objThis" RUNAT = "SERVER" PROGID = "This.Object"
Once the object reference was created, was quoted by the user from the application or virtual site loading within the page to complete the program code (in global.asa file a statement <OBJECT>). When the user session and the abolition of the end of the life cycle, it also cited the abolition of the object instance.
(3) on the scope and status
So that the scope object instance, or for the overall global environment for the user's session appeared to be a good idea, but in actual use when the need to consider some of the problems, one of which is the request of the user between a number of effective protection of the state . In other words, you can set some properties of the object, they use all the pages are shared. Because every time do not have to create a new instance and set its properties, so it appears to be a better approach.
In fact, Microsoft's recommended not to do so under normal circumstances, this thinking is the traditional thinking of the residual program. On the Web, it is necessary to face the biggest problem is that servers and Web applications and dynamic Web pages provided on how to deal with millions of website visitors. Component instance will reside in memory waiting for a specific user's page request, there may be hundreds of users visit the site at the same time, this is not an effective use of resources.
Windows 2000 provides a new COM + run-time characteristics, it can handle the creation of components, and the use of cache, but uses a share of the throughput of server resources to maximize the smallest way. Object instance is stored in the memory of where and how long the problem, it is best completed by the operating system itself, rather than a decision by the programmers.
In other words, the page where it is needed to create object instance, when the page is terminated to disappear. COM + to tidy up all these fragments, automatic processing of some of the complexity of the background work. If you want to learn more about this aspect of the content of Chapter 14 a more detailed study of the creation of components.
Of course, in some cases, we may be required by an object with the application layer and session layer of the scope, especially in the pages between the save state request. Discussed later on in the Dictionary object, there will be an example in this regard.

5.2.3 Server.CreateObject with distinction <OBJECT>
Server.CreateObject method to create an object instance immediately. In most cases this is what we want. <OBJECT> Elements and, for the first time an object is only created when the specified object instance. Therefore, if in the code to stop using the object does not create the object instance.
If the code only in certain circumstances the use of the object (which may depend on the value of the parameter request), which might be useful. Because if do not need this object, you can save server resources.
If, however, certainly need to create an object, use the Server.CreateObject method. <OBJECT> Elements used to create objects in the code helps to prevent the removal of the object called, forgot to phase out process Server.CreateObject line, of course, this is a careless programming.
Finally, keep in mind is that if the object is to use the Server.CreateObject method to create, you can from the conversation or remove applications, but the use of elements <OBJECT> created, is not.

5.2.4 components threading model
Use the page object or component should be considered another problem is that the object involved in a number of requests to respond to the behavior. In fact, in the ASP, this is the need to understand the subject of one of the most complex. A component of the threading model, combined with its scope, the impact of the component and application performance and efficiency, it also affects the ASP pages of examples.
Thread is executed by the processor system object for the component code from the definition of the completion of tasks. Each thread can be considered as a single binary instruction set. Windows such as multi-threaded environment, multiple threads can be run at the same time.
In fact, five thread model (including the introduction of Windows 2000 in the Neutral-threading model):
Single-threaded (single-threaded): a single moment in time there can be only one process to use a component.
Apartment-threaded (thread units): a number of processes can use a component, but there is only one thread at a specified.
Neutral-threaded (thread-neutral): the process can be used in a number of components, and can use a set of threads specified in any of them.
Multiple-threaded or Free-threaded (multi-threaded or free-threaded): can be used in a number of process components, and these processes can run on different threads.
Both-threaded (double thread): the target thread can be another unit can be used as free-threaded.
Here threading model does not explain the technical details behind this book the contents of the corresponding.
Thread unit components (such as the use of Visual Basic to create xml scripts or as a component) can be the role layer region of the page to run well, the role of regions in the session layer is also acceptable. In fact, the page layer, due to lower data processing costs, but also a very good run of double-threaded components.
Winodws 2000 thread in the model of neutrality and even to provide a better performance, although so far only a few such components and corresponding development tools.
If you need session layer components, the use of the available dual-threaded components. And the application layer, if necessary scope, may have been using double-threaded components.
However, Microsoft recommends that scope to avoid the use of session layer components, and even the application layer does not use the component scope, unless these components is absolutely necessary. So that the activities of components for more than page-level scope of the components required by the time provided by the COM + proxy characteristics are not helpful.

Asp Base Articles

Can't Find What You're Looking For?

Rating: Not yet rated


No comments posted.