ASP 3.0 Object Model Overview

Source: Internet
Author: User
Tags contains object model reference
Object

Before studying the details of the ASP from a programmatic perspective, you must look at the ASP object model. This is very important. Because if you do not do the same work on ASP 2.0, you must consider how the ASP generates the page.
Object Environment Concept
In version 1. In 0, it is an exciting new way to add some dynamic content to a Web page. You can use it to read data from the database or manipulate the values that are sent from the browser. In ASP 2.0, a number of very noticeable changes have taken place, adding Microsoft Transaction Server (MTS), which can handle multiple concurrent component instances and provide further scalability. This means that the whole concept of Dynamic Web page work has changed.
On this basis, MTS allows the use of transactions that are distributed across multiple components, applications, and services. For example, an ASP page can update a local database when a message is sent to a remote computer through the messages Queue Service (formerly MSMQ). If a portion of the entire transaction fails, the entire process is restored to the original state of the system.
MTS, as well as the increasingly extensive use of components, has led to the development of Web applications using ASP, rather than a single, simple dynamic page. The environment for this ASP page is available within the component that is instantiated by the ASP script. The environment contains all the internal ASP objects (which we will soon encounter). Therefore, you can use it to obtain the information requested by the user and create a corresponding response.
Because this environment contains the entire ASP's object model, it allows programmers more control over the complexity of the processing of the ASP and the components used. It is generally assumed that the "root" of the object model is the request, response, and other internal objects, and that the real case is (since ASP 2.0), and this root is an object known as the object context.
1. Environments that reference ASP pages
In ASP 1.0, the only way to reference an environment is through an ASP-generated event: OnStartPage, each time the ASP page is started. This event provides an object context object for an ASP page with an argument. Within a component, a reference to the object context can be captured in a global variable for code use. For example, the following VB code stores the environment in a local variable called the obj context.

As you can see from the code above, in ASP 1.0, the environment for an object is the scripting context type, which is an object type defined in ASP.DLL and is used to create code that references a file ASP.dll. It is clear, however, that controlling transactions and providing efficient out-of-process component execution (one of the tasks of MTS Management in ASP 2.0) must take a different approach. The page environment must be explicitly available, without having to keep a reference to it at the beginning of each page.
Therefore, in ASP 2.0, Microsoft introduced object context objects. However, since the scripting context still works through the OnStartPage event, many component creators take into account the backward compatibility of the program, avoiding the use of ObjectContext objects, and even preferring to reduce performance. Now, with ASP 3.0, things have changed. In Windows 2000, MTS is incorporated into the operating system as part of COM + technology, and will be used in the default state for any component instantiated in the ASP unless it is explicitly decided to avoid it.
2. Referencing ObjectContext objects
Starting with ASP 2.0, you have been able to obtain a reference to the current page environment through the GetObjectContext method provided by ASP. This means that you no longer have to store a reference to the environment through a page, and you can get it whenever you need it.

This allows our objects to become stateless (stateless), in other words, you do not need to keep a reference to any values or objects when you have finished executing a particular method. If you have not used ASP 2.0 and MTS before, this may seem like a somewhat esoteric concept. However, it is extremely important that we will discuss in the next section a great deal of detail on this issue.
ASP built in Objects
Seeing how the ASP provides a "root" object in the form of an object context, you can see how other built-in objects are built on it to provide access to client requests, the responses we create, and other objects that make scripting easier.
The original scripting context object is still in use and the OnStartPage event is available, but it is now obsolete and should be used only for pages that are executed on IIS 3.0 with ASP 1.0, or when absolute backward compatibility is required.
The two main built-in objects provided by ASP directly map two behaviors of the client when accessing the Web server. The other 4 provide additional functionality that is useful for scripting. Each object provides a series of collections, properties, and methods, which are described in a later section.
The Request object provides the script with all the information that the client provides when requesting a page or sending a form, including HTTP variables that can identify browsers and users, a cookie that stores their browser corresponding to the domain, and a value appended to the URL (query string or page < The value within the HTML control in Form > Segment). It also gives us the ability to access certificates through secure Socket Layer (SSL), or other cryptographic communication protocols, and provides properties that help you manage connections.
The response object is used to access the response that was created and returned to the client. It provides the script with HTTP variables that identify the server and performance, the information that is sent to the browser, and any information that will be stored in the cookie. It also provides a series of methods for creating output pages, such as the ubiquitous Response.Write method.
The Application object is created when loading an ASP DLL in response to the first request of an ASP page, and it provides a reference to the storage space used to hold variables and objects, and can be used for all pages that any visitor can open.
A unique session object is created when each visitor first requests an ASP page from a Web site or Web application, and it is persisted to the default end of the deadline (or the duration of the aborted by the script). It provides a space for the reference of variables and objects like the Application object, but only for pages that the current visitor opens during the life of the session.
The server object provides a range of methods and properties that are useful when scripting with ASP. The most commonly used is the Server.CreateObject method, which allows us to instantiate other COM objects on the server on the current page's environment or session. There are also ways to translate strings into the correct format for use in URLs and HTML, which is accomplished by converting illegal characters into correct, legitimate equivalents.
The ASP Error object is a new object in ASP 3.0 that is used by the get-last error method of the server object. It provides detailed information about the last error that occurred in the ASP.
These objects can be thought of as members of a hierarchical relationship based on the object context objects, which helps to understand their relationship to the process of accepting and responding to customer requests, as shown in Figure 1-2 0. The diagram shows the relationship between ASP and the process of creating and servicing ASP pages.
We will look at each of the objects in a later section and how they are used.




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.