ACTIVE SERVER PAGES 2. About this guide This practical guide aims to be a complete programming guide as well as a reference for. and the topic of designing Active Server Pages is a trademark of experience building real-world web sites using Active Server Pages. Request PDF on ResearchGate | Active Server Pages | Active Server Pages ( ASP) and soundofheaven.info are two popular server-side programming technologies.
|Language:||English, Spanish, Dutch|
|ePub File Size:||16.60 MB|
|PDF File Size:||15.38 MB|
|Distribution:||Free* [*Regsitration Required]|
Active Server Pages soundofheaven.info - Ebook download as PDF File .pdf), Text File .txt ) or read book online. Microsoft® Active Server Pages (ASP) is a server-side scripting environment that you Beginners can learn what scripting is all about. Active Server pages enables server side scripting for IIS with native support for both VBScript and Jscript.” (2). In other words, ASP is a. Microsoft technology that . Active Server Pages were introduced by Microsoft in as a download- Figure Active Server Pages are enabled by adding script.
Some components do not require transactions. Introduction to Active Server Pages: To declare a variable. For more information about session pooling. Thus, a user viewing this script before For the Request object.
Active Server Pages Guide Page 16 of browser. Write x. Using Variables and Constants file: When you use JScript keywords in scripts. One consequence of caseinsensitivity is that you cannot distinguish variable names by case. JScript is case sensitive. These characters should be used on each comment line.
This script will work. Unlike HTML comments. This script will fail. Declaring and Naming Variables Follow the rules and guidelines of your scripting language for naming and declaring variables.
Even if you are not required to declare a variable before using it. To declare a variable. To declare a variable in VBScript. Declaring a variable means telling the script engine that a variable with a particular name exists so that you can use references to the variable throughout a script. A variable is a named storage location in the computer's memory that contains data. JScript Although JScript does not usually require variable declarations.
The data contained in a variable is called the variable's value.
For more information on these commands. Variables give you a way to store. JScript will assume that that you referring exclusively to the global variable. For more information on the var statement. A variable declared outside a procedure has global scope. It cannot be accessed by anything outside the procedure. If you do not declare variables. A variable declared inside a procedure has local scope. When the procedure call sets Y to 2. Note Limiting variable scope to a procedure will enhance performance.
In this case. Variable Scope The scope. If you declare variables. Modifying the value of one will not modify the value of the other. Application-scoped variables are available to all pages in one ASP application that are requested by any user. It is easy to forget that you must use different names for variables used in the main script and in the included script unless you declare the variables.
To make a variable accessible beyond a single page. Session-scoped variables are available to all pages in one ASP application that are requested by one user. The included script is contained in a separate file but is treated as though it were part of the including file. The following example uses the output directive to display the current value of Session "FirstName": This is particularly important if you use the include statement to include files into your. Session Scope To give a variable session scope.
You can also create object instances with session or application scope. ASP provides two built-in objects into which you can store variables: Session variables are a good way to store information for a single user.
Application variables are a good way to store information for all users of a particular application. Using Constants A constant is a name that takes the place of a number or string. To declare a type library. Active Server Pages Guide Page 20 of those preferences to determine what page to return to the user. A component can declare constants in a component type library.
Once you have declared a type library in your. The following example uses the output directive to display the value of Application "Greeting": Some of the base components provided with ASP. Application Scope To give a variable application scope. Write to access the named entry from any subsequent page in the application.
In previous versions of ASP. The use of the include directive to include constant definitions is still supported. Components might not provide constant definition files in future releases of ASP. Recordset" rstCustomerList.
In the following example. If you want to use your constants on more than one. ASP's effectiveness can be extended by using it to generate or manipulate client-side scripts.
In VBScript. In JScript. Defining Procedures file: You can define your own procedures and call them repeatedly in your scripts. You can place procedure definitions in the same. Innovative use of this technique can also reduce round-trips and server processing. A procedure is a group of script commands that performs a specific task and can return a value. Calling Procedures To call procedures. Commands that are not part of a procedure may cause unpredictable results because these commands may be executed in an uncertain order.
Write "You called MyFunction. The commands in the script block must form one or more complete procedures in the chosen scripting language. You can specify any language for which you have the scripting engine installed with the server. If you do not set this attribute.
To specify JScript. To specify VBScript. Write to send content to the browser. The following example illustrates creating and calling procedures by using two different scripting languages VBScript and JScript. If you use Call syntax to call any built-in or user-defined function. If you omit the Call keyword. Indexed access is generally used to iterate through a collection. You can access an item in a collection by its unique string key. If an item with a particular name appears only once in an object's collections.
The position of an item will also move as the collection is modified. Collections are data structures similar to arrays that store strings. ASP searches the collections associated with an object in a particular order. It can also hold any objects instantiated by calling Server. Suppose you have stored the following user information in the Session object: Most of the ASP built-in objects provide collections. Accessing an Item by Name or Index You can access a specific item in a collection by referencing its unique string key.
The index associated with an item might change as items are added to or removed from the collection. You can also use a shorthand notation to access items by name. Unlike arrays. Next statement. Contents Response. Write Session. Iterating through a Collection You can iterate through all the items in a collection to see what is stored in the collection or to modify the items.
For the Request object. Dim strItem 'For each item in the collection. You use the Count property to specify the end value of the counter. For Each strItem In Session. Active Server Pages Guide performance: Count 'Repeat this loop until the counter equals the number of items 'in the collection.
Dim intItem 'Repeat the loop until the value of counter is equal to Each statement to access the items you stored in the Session object: You must supply the collection name when you iterate through a collection.. ASP supports the Count property for a collection. Dim lngItem. The moveNext method moves to the next item in the collection. For greater efficiency when using the Count property with a JScript for statement. The Cookies collection of the Request and Response objects can thus hold multiple values in a single item.
Cookies collections. The following example demonstrates this technique: Subkeys are supported only by the Request.
These subitems. Cookies supports only read operations. The following creates a regular cookie and a cookie with a subkeys: Cookies and Response. Cookies supports only write operations.
The atEnd method indicates whether there are any more items in the collection. That way. For Each Cookie In Request. HasKeys Then Response. Cookies "User" file: Write Cookie If Request. This technique is demonstrated in the following example.
Cookies Cookie. You can avoid this situation by first checking to see whether a cookie has subkeys by using the HasKeys attribute of the Cookies collection.
Cookies Response. Dim Cookie. Cookies Cookie Response. You can also enumerate all the cookies in the Request. Cookies collection and all the subkeys in a cookie. For Each Subkey In Request. Subkey 'Display the entire cookie collection. When you iterate through a collection that contains objects. Cookies "UserId". They do not support the Add method. For more information about instantiating objects in this manner.
StaticObjects Response. The QueryString collection was first to define the case of this key. Iterating through a Collection of Objects The Session and Application collections can hold either scalar variables or object instances.
Examine the following script: The Contents collection holds both scalar variables and object instances created by calling Server. Because references to collection values are independent of the case of the key name. QueryString "User" Page 30 of The case of the key name is set by the first collection to assign a value to the key.
You could iterate through the StaticObjects collection to retrieve object properties: When the user submits HTML information. Once again. Text boxes. COM components. In this topic you will not only learn how to create basic form processing scripts.
The form also contains an hidden input tag not displayed by the Web browser that you can use to pass additional information to a Web server. Using the ASP Request object you can create simple. Write "This is your first visit to this Web site! A static. You are 30 years old! This is your first visit to this Web site! The QueryString collection also has an optional parameter that you can use to access one of multiple values that appear in the URL request using file: The first two methods operate in the same way as forms that interact with other Web server programs.
The third method is a particularly useful and will be demonstrated in the Validating Form Input section.
Hello Clair Hector. Count To display the multiple values types. If you need to send a large amount of information from a form to a Web server. The Form collection stores values in a manner similar to the QueryString collection. QueryString "Food".
Write Request. You can also use the Count property to count the number of times that a specific type of value appears. Apples Olives Bread You can also display the entire list of values as a comma-delimited string by using the following: Some Web servers tend to restrict the size of the URL query string.
The POST method. The following client-side script validates user—input in this case. In general. Form "Food". Validation scripts can check for such things as whether the user entered a valid number or whether a text box was left empty.
Imagine that your Web site includes a form that enables users to compute the rate of return on an investment. You will probably want to verify whether a user has actually entered numerical or text information in the appropriate form fields. Beyond prompting users more quickly about input errors. A particularly advantageous way of carrying out server-side validation is to create a form that posts information to itself. Important If your are using JScript for server-side validation.
That is. The input is returned to the same file. Users who do not immediately understand this information may become frustrated. Using this method of processing and validating user input can greatly enhance the usability and responsiveness of your Web based forms. Web-based forms forward requests to a separate Web page containing error information.
Transfer "Complete. Form "Password". The following script illustrates the correct way to assign variables with JScript: If you are new to scripting. ASP comes with base components that you can use immediately. ASP also provides a set of base components that you can use to greatly enhance your scripts.
Form "Name" 1. Components provide functionality that you use in your scripts to perform specialized tasks. COM components are the key to building powerful. COM components execute common tasks so that you do not have to create your own code to perform these tasks.
Active Server Pages Guide Page 36 of local variable. Form "Name". Without parenthesis. Write "Your name and password are different. Write "Your name and password are the same. Components can be combined with other components even across networks to create a Web application. The Ad Rotator component provides one object. Additional components can also be obtained from thirdparty developers.
For the base components provided with ASP. Each object has methods programmed procedures and properties behavioral attributes. Components provide one or more objects. COM components are also known as Automation servers. If you are familiar with COM programming.
Because the verification is isolated from the order process. To use an object provided by a component. Use the ASP Server. To run on the Web server. Visual Basic. Once you have installed a component on your Web server. When you create the object instance. If you are a Web application developer. Microsoft's powerful scripting technology that you can use to create COM components. The following is an example of a Windows Script Components.
ASP cannot track your use of the object in your scripts. You must use the ASP Server. To use this Windows Script Component in a Web page. Method parameters file: CreateObject "ConvertTemp. The syntax for calling a method is: These objects are automatically created for you when the ASP request starts processing. Unlike using the objects provided by a COM component. Calling an Object Method A method is an action you can perform on an object or with an object. For a complete description of the built-in objects.
See Working with Scripting Languages for more information. Properties define object characteristics. Property You can sometimes read and set the value of a property. If your language does not. CreateObject to create an instance of a Java class. To instantiate a class with monikers. You can then use Server. Setting an Object Property A property is an attribute that describes the object. The syntax is: Method syntax. The following expression specifies no border: CreateObject can also access the ASP built-in objects and participate in a transaction.
The scope of an object determines which scripts can use that object. If you must create objects in a loop. Any script command in the same ASP page can use a page-scope object. You can change the scope of an object. To use Java monikers. Thus an object has the scope. Creating Objects in Loops In general.
This topic explains how to work with page scope objects and how to change the scope of objects. The recommended scope for most objects is page scope. The object is accessible to any script commands on that page. The following example creates a sessionscope instance of the Browser Type object of the Browser Capabilities component: Giving an Object Application Scope file: CreateObject method for session-scope objects.
CreateObject method to store an object in the Session built-in object. To give an object session scope.
The following example stores an instance of the Browser Type object in the Session object. Session scope is used for objects that are called from multiple scripts but affect one user session.
CreateObject method instantiates the object immediately. The Server. You should give objects session scope only when needed. If you do use session scope. In the Global. Active Server Pages Guide Page 42 of Giving an Object Session Scope A session-scope object is created for each new session in an application and released when the session ends.
CreateObject method on an ASP page to create a session scope object instance. Performance Issues in this topic. Some utility objects. To give an object application scope.
This object is shared by all client requests. GetAdvertisement "CustomerAds. CreateObject method in an. In many cases. Active Server Pages Guide Page 43 of An application-scope object is a single instance of an object that is created when the application starts.
CreateObject to store an object instance in the Application built-in object. Session scope objects Objects marked Both will give you the best performance. User-defined JScript objects are supported in ASP server-side scripts and work well when they have page scope. Page scope objects Objects marked Both or Apartment will give you the best performance. CreateObject method to store objects marked Both in the Application object.
For more information about scoping variables. Using single-threaded or apartment-threaded objects will cause the Web server to lock the session down to one thread. Freethreaded objects do not lock down the session. Advanced Information: Performance Issues The threading model of a component may affect the performance of your Web site.
The object instance is created when your script uses the new operator to invoke the constructor. Because you may not always have control over the threading model of the objects you use. In this way. CreateObject method to store objects in the Session object. User-Defined JScript Objects You can create your own JScript object by defining a constructor function that creates and initializes the properties and methods of the new object.
In particular. Application scope objects Objects marked Both. Active Server Pages Guide Page 44 of objects is to use session or application scope variables that pass information to objects created at the page level. You can.
Write to send content back to the user. Active Server Pages Guide Page 45 of For more information on threading models and their implications for component performance. You can also explicitly send content to the browser by using the Response object.
Content that is not within scripting delimiters is sent directly to the browser. As a script in an ASP page is processed. Write when you do not want to break up a statement with delimiters or when you want to build the string that is returned to the browser. These file types may be used as a reference when you choose to manually set the content type with ASP. Redirecting the Browser Instead of sending content to a user.
Setting the Content Type When the Web server returns a file to a browser. Redirect "Register. This enables the browser to determine whether it can display the file itself or whether it has to call another application.
To see the content types already defined by your Microsoft Web server. Redirect does not need to be followed by Response. Transfer to jump between the pages of an application depending on state information: ASP enables you to turn buffering on or off.
Place the Response. Transfer you can directly transfer requests for. Request information is then made available to the destination file when it begins execution.
During execution. Redirect statement at the top of the page. Redirect to redirect a browser requires a round-trip.
Active Server Pages Guide Page 47 of server-side scripts which are processed before any content is sent to the user are said to be buffered. If you use Response. With Server. The server then adds this request to the request queue along with other client's requests that arrived in the meantime. Redirect from the middle of a page.
For a busy Web site. You can use the Server. During a transfer. If you want to use Response. Transferring Between. Transfer sends requests from one executing. Also note that Response. Buffer property. Redirect method. Redirect after content or headers have been returned to the browser. Transfer method to transfer from one. Buffering Content By default.
Execute to do dynamic inclusion of. Just as with Server. ASP also provides the Server. Page 48 of You can also use Server. This process is known as buffering. Transfer to transfer between.
If you are familiar with VBScript. The advantage of buffering your. Execute "HTML. You can use the Buffer property of the Response object to disable buffering.
Execute as analogous to a procedure call. Active Server Pages Guide requested file. Execute command that you can use to transfer to a file.
Having the proxy server process requests and cache pages reduces the load on the network and on the Web server. For long or complicated scripts. Depending on your application. Active Server Pages Guide Page 49 of buffer using the the Clear method of the Response object to send different content to the user.
You can use the Internet Information Services snap-in. The following example uses both of these methods: Allowing Proxy Servers to Cache Pages Your application may be sending pages to a client through a proxy server.
The proxy server caches HTML pages so that repeated requests for the same page can be returned quickly and efficiently to browsers. Certain properties and methods. A proxy server acts on behalf of client browsers to request pages from Web sites.
Clear Server. Buffering is turned on by default for ASP applications. If the Buffer property in a script is set to TRUE without also calling the Flush method to immediately send buffered content to the browser.
The benefit of writing scripts in this manner is that server performance is improved because the server does not have to create a new connection for each client request assuming that the server. Buffer to prevent the Web server from returning the HTTP header before a script can modify the header.
Expires and Response. Although caching works well for many HTML pages. Clever use of channels for distributing Web based information especially on intranets can help to centralize information as well as reduce server traffic.
CacheControl is the string "Private". The channel schedules the user's computer to periodically connect to a server and retrieve updated information. For more information about channels. Expires property before any HTML tags or buffer the page. If your application returns personalized information. This retrieval process is commonly referred to as client pull because information is "pulled" in.
Buffer to buffer the page. Preventing Browsers from Caching Pages Each browser version has its own rules for determining whether to cache pages. To allow caching. When new information is made available at a particular Web site. Because HTTP headers must be sent to the browser before any page content is sent.
Expires to set the Expires header: Information that is even one hour old might not be accurate enough. You can allow caching for certain pages by using the Response. To prevent a browser from caching ASP pages.
The default value of Response. When ASP reads a file with a.
Commands in the. WebDAV holds great promise for making the Web into seamless. When you write a server-side script to create a channel definition file. With the IIS 5. An XML-based channel definition file. Active Server Pages Guide http: Here is an example of how you might use channels. When submitted. The following HTML form asks the user to select channels. If you do not use the. Page 51 of Using ASP. Using the Virtual Keyword Use the virtual keyword to indicate a path beginning with a virtual directory.
You can also use the file keyword with the syntax. A relative path begins with the directory that contains the including file. Server-side include directives give you a way to insert the content of another file into a file before the Web server processes it.
To insert a file into an. ASP implements only the include directive of this mechanism. Location of Included Files ASP detects changes to an included file regardless of its location and inserts the files content the next time a browser requests an. Included files do not require a special file name extension. Active Server Pages Guide Page 53 of includes this file. Nor can a file include itself.
Tips and Cautions An included file can. ASP includes files before executing script commands. For better security. Web server Read permissions are applied to all files. Important By default. ASP detects such loop or nesting errors. ASP provides a unique solution for the problem of managing session information. Active Server Pages Guide Page 54 of functions and variables that are unused by the including script. One of the challenges to developing a successful Web application is maintaining user information over the course of a visit.
HTTP is a stateless protocol.
This inability to remember previous requests means that it is this difficult to write applications. Note Timeout only applies to sessions that have state. This type of session automatically ends after the request is processed and is recreated on the next request from the same browser. This value is 20 minutes by default.
Starting and Ending Sessions A session can begin in four ways: A new user requests a URL that identifies an. A user requests an. Set this value according to the requirements of your Web application and the memory capacity of your server. You can change the default for an application by setting the Session Timeout property on the Application Options property sheet in the Internet Information Services snap-in.
A long session timeout period can result in too many open sessions. A new session automatically starts whenever the server receives a request that does not contain a valid SessionID cookie. A session automatically ends if a user has not requested or refreshed a page in an application for a specified period of time.
During a stateless session the Session object does not contain content or static objects. A user stores a value in the Session object. ASP minimizes the number of cookies sent to the browser. ASP can store information for the user in a "locker" on the server. Each time that ASP receives a request for a page. At the beginning of a new session. ASP reuses the same cookie to track the session. Abandon will execute within the context of the session being abandoned. The user's SessionID cookie.
ASP will not send the session cookies under the following conditions: If an application has session state disabled. A number produced by a complex algorithm.
After Session. ASP begins a new session using the same cookie. You should also note that SessionID cookies are not intended to provide a permanent means for tracking users across multiple visits to a Web site. If an ASP page is defined as sessionless. If you want track users who visit your Web application over a longer periods. The SessionID information stored in the server computer's memory can be easily lost.
Abandon has completed execution. The SessionID cookie is similar to a locker key in that. The only time a user receives a new SessionID cookie is when the server administrator restarts the server. After storing the SessionID cookie in the user's browser. By reusing the SessionID cookie. By using the Contents collection's Remove method.
The following script illustrates how to use the Remove method to purge an item. In such a case it may be expedient to update the Session object by deleting inappropriate values.
At times. Active Server Pages Guide Page 57 of cookie in a user's Web browser and saving the cookie information to a database. The Session object's Contents collection contains all of the variables that have been stored that is. To store a variable in the Session object. You can store scalar variables and object variables into the Session object. The following script demonstrates how to cycle through values stored in the Session object and conditionally remove values by index: ASP creates a new user session on that server.
RemoveAll Using the Remove method you can choose to delete items by name or by index. If all links in your application pages are relative. Load balancing makes it difficult to maintain session information on a cluster of Web servers.
On cluster of Web servers where many Web servers share the responsibility for responding to user requests user requests will not always be routed to the same server. To use ASP session management on a load-balanced site. Redirect "http: The load balancer routes the request to a specific server.
Contents If Session. A browser must request pages from the same Web server for scripts to access session information.
Cookies creates a new one. Cookies does not specify a key name. Cookies specifies key names and values. ASP scripts can both get and set the values of cookies by using the Cookies collection of the Response and Request objects.
Cookies collection. An indexed cookie value is assigned a key. Setting Cookies To set the value of a cookie. Cookies "VisitorID". The next time the same browser requests a page. Cookies allow a set of information to be associated with a user. Cookies and set the date to some date in the future: If the cookie does not already exist. To save the cookie.
Getting Cookies To get the value of a cookie. When the browser requests a file stored in the same location as the path specified in the cookie. Many Web browsers. Cookies collection's Path attribute. Cookies "Purchases". Make sure all URLs to. To specify a path for a cookie other than the default application path. This means that if the case of the path of a requested file differs from the case of the stored cookie path. You can use the following statement to set the cookie path so that the user's Web browser will forward a cookie whenever the browser requests a file from your server.
Add hidden values to a form. Preserving State without Cookies Not all browsers support cookies. Even with browsers that do support cookies. To turn off session support. Sessionless pages do not carry out the following: When sessions are enabled.
If your application needs to be responsive to browsers that don't support cookies. Create Session objects. If you are not using ASP session management. Send session ID cookies. The form passes a user identification value. There are two general ways to do this: Add parameters to a URL's query string. Active Server Pages Guide Page 61 of distinguishing between applications. For more information about ADO.
OLE DB is a system-level programming interface that provides standard set of COM interfaces for exposing database management system functionality. Because ASP executes session requests in sequential order. It's not just a technology, though — to get the best out of ASP, you'll be using it in tandem with HTML, and with one or more of the web's simple scripting languages. The book will teach you everything you need to create useful real-world applications on the web.
This book is for anybody with a grasp of HTML who wants to add more to their web pages. It also covers VBScript — a simple Internet programming language. This makes it the ideal first step for the aspiring web professional.
It's also useful for more experienced programmers looking for a practical, no-nonsense introduction to ASP and programming for the web. To get the most out of this book you should be running Windows , which includes ASP 3 — the latest version of this popular technology.
All Titles. US Amazon. UK Amazon. This title is out-of-print and not currently available for purchase from this site.