Tutorials to .com

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

Advanced Programming ASP 3.0 (23)

Print View , by: iSee ,Total views: 24 ,Word Count: 3406 ,Date: Sat, 25 Apr 2009 Time: 10:48 PM

Chapter 6 of the activities of server components
Previous chapter, we have studied two different types of objects: one object model is the asp built-in part, and the other is the script run-time library provided by the object. This chapter will introduce the third type of object can be used to ASP, known as the activities of the server component (or server component is called).
These components in many occasions just like in the browser or in the programming environment like Visual Basic for client-side script in the traditional, like ActiveX controls, but these components can be run on the server, rather than can only run on a the target client.
The question now is: will these components come from? One of which is from conventional ASP / IIS installation process, while the other part from the Web for free or paid access. The present chapter discusses the various components of ASP's main purpose, and then introduced the availability of several examples of other components. Once the use of these activities feel easier server components, you will easily be embedded in other vendors products to your ASP page. After this chapter there is a list of third-party components, this book describes how the back will also create their own components.
There are also components for ASP, but not ready to discuss in this chapter. Dynamic Web sites use technology is one of the basic release directly from the database management system and other types of data storage available information, the purpose and from a database or other data storage in data collection and data into the demand for programmers to develop server-side programming. In order to use ASP to accomplish these tasks, we can take full advantage of is called ActiveX Data Objects (ActiveX Data Objects, ADO) library collection of components. Because it involves a lot of content, it is difficult to clearly set out in this chapter, we must also consider the other components, this book from the beginning of Chapter 8 on the relevant content.
To discuss the contents of this chapter are:
In the ASP server components used in the difference between other objects.
A brief description of how to instantiate objects and invoke server components.
ASP 3.0 and IIS can be installed to provide the components, such as AD Rotator, Content Linking, Page Counter and Tools and other components.
Some of the components provided by third parties.

6.1 Scripting Object comparison with the server components
The previous chapter has described a variety of script objects, these objects for ASP / IIS is running from the script library (scrrun.dll) obtained, it is important not to these objects with the server component (that is the subject of this chapter) with confusion.
Server component is usually in its own DLL or executable file to achieve, for example, to be discussed in this chapter "Content Linking" components, is achieved by nextlink.dll. Once installed on the server and registered the DLL file, then the object of its ASP can support the use of any scripting language. Components and system environment as shown in Figure 6-1:
Figure 6-1 Components of the relationship between environment and system

The use of components of the server components
The previous chapter has introduced the objects and components in common example of a page method, the use of server components and using a script run-time library exactly the same object, the only difference is that unlike the script object, usually as a server component to achieve a separate DLL file, and may require the use of the installation before running a program, or manually register the component (if these components installed by default in ASP unregistered).
1. CreateObject method
Generally speaking, an ASP in the ASP page to use the built-in Server object CreateObject method to create an object, such as:
Set objThis = Server.CreateObject ( "this.object") 'in vbscript
Or:
var objThis = Server.CreateObject ( 'this.object'); / / in jscript
This will create objThis in the variables of the object, and then can use the script object; In other words, can be in the code as needed to control its attributes and call its methods.
2. The use of elements <OBJECT>
Orders can also be used to create an object element <OBJECT> The method also applies to pages in the Web browser to create the object. ASP to support the special element in HTML <OBJECT> to achieve, and we can use this method to place the page in an object. In general. Asp files or scripts define a component instance of the object, use the following statement:
<OBJECT RUNAT = "SERVER" SCOPE = "PAGE" ID = "objThis"
CLASSID = "CLSID: OACE4881-8305-11CF-9427-444553540000">
</ OBJECT>
We use the SCOPE attribute to set the scope of the object, the option is "SESSION", "APPLICATION" and "PAGE". If the ordinary. Asp files <OBJECT> elements used, then must also use the "PAGE" attribute, and ignore the SCOPE attribute to create the object because it is only an example of the use of the page. If you use the global.asa file <OBJECT> element, the object can be created in the current session or the whole application, so SCOPE set to attribute "SESSION" and "APPLICATION".
3. Detection of the existence of object instance
Frequent error is an attempt to create a not installed (or registered) of the object instance, or in the CreateObject method or the use of elements <OBJECT> wrong ProgID. By default, ASP will be an error and stop the implementation of the page.
To add some code pages, during his visit before the test object is necessary. In VBScript, you can do this by: Turn off the default error handling, and then view the object using the IsObject function really refers to an object:
'In VBScript:
...
On Error Resume Next 'turn off default error handling
Set objThis = Server.CreateObject ( "this.object")

If IsObject (objThis) Then
'the CreateObject method succeeded
On Error Goto 0 'turn the default error handling back on
...
'rest of the script goes here
...
Else
Response.Write "Sorry, this page cannot be accessed at present"
Response.Flush
Response.End
End If
...
In the JScript language, you can use JScript 5.0 script engine in the new error handling features, which are described in Chapter 1 have been.
/ / In JScript:
...
try (
var objThis = Server.CreateObject ( 'this.object');
...
/ / Rest of the script goes here
)

catch (exception) (
Response.Write ( 'Sorry, this page cannot be accessed at present');
Response.Flush ();
Response.End ();
)
...

6.2 ASP / IIS to be installed components
ASP / IIS installed, including a series of standard server components, these components in the IIS documentation has been described as components can be installed (installable component), even though by default it is safe to install them. However, the name may also be used only in earlier versions of ASP's name. In previous versions, the need to manually install these components. Now, if the effect is to give them a proper name, can be called "component can be instantiated."
It should be noted that in Chapter 8 will introduce a specific component can be installed, that is, ADO components. Section behind the other components are used as the specific services or the server part of the application installed. Such as Collaboration Data Objects (Collaborative Date Objects, referred to as CDO and CDONTS) component for the mail server and e-mail messages. The remainder of this chapter will discuss how to use other common components of a strong Web site or Intranet to provide enhanced functionality.
In Windows 2000 in the WinNT \ System32 \ intesrv \ directory under the ASP can be found in these components can be installed, the directory also placed a number of components required profile. Listed in alphabetical order following a number of components.
Ad Rotator component is used to control the emergence of a clickable image, such as advertising or the title. Stored in the configuration file using the information, Ad Rotator to in accordance with the provisions of the ratio profile shows different images, but also have to be re-click ads to the appropriate URL, as well as record the characteristics of image clicks.
Browser Capabilities component using UserAgent string made by the browser to the server, used to identify the corresponding browser. It provides browser-specific features to reflect a series of attributes, such as whether to support the script, cookie or java applet.
Content Linking a series of components used to provide convenient navigation of the page, the page can be changed or updated without having to edit each page. The components of a text file (containing the page URL and display order), so that a specific order to create a number of linked pages is easy.
Content Rotator component uses a configuration file to specify other pages inserted into the HTML, text or code, in accordance with the specified configuration file indicates that the content of any part of it.
Counters components to create, increase and permanently stored in all the script code used in integer counter values.
Logging Utility component provides for the Web server log files, and allow an ASP page to read and update the data. This is in Windows 2000 with IIS 5.0 and ASP 3.0 new features.
MyInfo component for the entire site to visit in the name / value pairs of storage provides a storage space, the data on the server in xml format for storage of text files (as distinct from the application scope, the data in the scope of Web site remain outside).
Page Counter component records the number of visits a page, the page can be used to track clicks.
Permission Checker component to help prevent when a user tries to access is not correctly set the permissions of resources caused by script error.
Tools component provides a number of pages can be used in the methods used to test the existence of a file to handle HTML form to generate a random integer. There are also used in Apple Macintosh computers on the way to check whether there is a server plug-ins, check whether the current user for the site owner.
Another by the IIS / ASP to provide the components, that is, Status components, Macintosh computers could only be used for personal Web server. The book does not involve any of the components, to provide details about the components, can be HTTP: / / localhost/iis/htm/asp/complqt0.htm access to ASP / IIS document provided by IIS 5.0.

6.2.1 use the sample page
This book has provided a series of sample pages to illustrate the use of all of these components.
From the Wrox Web site to download the examples page, and run on your computer. Download the file in a subdirectory Chapter06 will find this chapter of the program code used.
Before running the example page to ensure that the components MyInfo and Counter "global" instance of the code has been included in the default Web site's global.asa file. In the sample file provided global.asa file required code, the code can be added to the existing global.asa file, do not need to replace the entire document.
<! - Declare instance of the ASP Counters component with application-level scope
->
<OBJECT ID = "objCounters" RUNAT = "Server" SCOPE = "Application"
PROGID = "MSWC.Counters">
</ OBJECT>

<! - Declare instance of the ASP MyInfo component with application-level scope
->
<OBJECT ID="objMyInfo" RUNAT="Server" SCOPE="Application" PROGID="MSWC.MyInfo">
</ OBJECT>
Examples of documents the main menu page (Default.asp) use the Content Linking component to create a page for each example of the link. Therefore, we will first look at the components, is also involved in the Ad Rotator component Counters and related issues.

6.2.2 Content Linking Component
Content Linking component of the site is very useful tool, which provides the content of the page or site that contains the same list of links to other pages of the page. It automatically shows the current page URL and stored in the server's text file list of matching pages and pages to allow users to order the list by the positive and negative views. In other words, even if the visitor has been in the content page and click on a link in the list are viewing a page, the component will still be identified by the page to visit the location in the list.
Because all the details in a text document, web site maintenance as well as links to pages only need to edit the text file. For example, we can link through the list of the contents of the document pages to rearrange the order, to change their order.
1. List the contents of the document link
Documents include a list of the contents of links on a simple display of the URL list in chronological order, but also provides a description of the contents of the page for the link text to display. If necessary, can also be increased for each page of the Notes, the Notes can help identify the link, but the visitors for the Notes is not visible.
List of documents for each page contains a text line. Each line from the URL, description and notes composed in part by the Tab character (not space, or document will not be able to work) separated the end of the final carriage return. For example:
newpages.htm New additions to our site we update this weekly
offers.htm Special Offers for this week we only update this monthly
register.htm Registration for new users
main.htm The main forum and chat area must be registered first
index.htm Back to the contents page
Please note that the target URL must be a relative or virtual path to explain the physics, such as the forum \ enter.htm. URL can not use "http :","//" or" \ \ "as the beginning of the above If you want to create such a menu contains an absolute URL, you can use ASP to build a redirect page, and link the content of its list of documents designated, for example, the establishment of a redirect.asp pages, contains the following code:
<%
'redirect the request to the site specified in the query string
Response.Clear
Response.Redirect Request.QueryString ( "url")
%>
List of links in the content of the document redirect.asp use of the following documents:
redirect.asp? url = http://www.cyscape.com/ CyScape BrowserHawk Web Pages
redirect.asp? url = http://www.softartisans.com/ SA fileUp Component Pages
redirect.asp? url = http://www.stonebroom.com/swindex.htm Stonebroom RegEx Pages
2. Members of the Content Linking Component
Content Linking component provides eight methods, such as shown in Table 6-1. These methods can retrieve documents from the content of the entries in the list of links, not only vis-à-vis the current search entry page, you can also use its search index entries absolutely. The first entry is the No. 1 of the index.
Table 6-1 Content Linking Component and Description
Methods
Description

GetListCount (links_file)
Links_file return to document the number of entries

GetListIndex (links_file)
Return document links_file index of the current page number

GetNextURL (links_file)
The return of documents in the next links_file page URL

GetNextDescription (links_file)
The return of documents in links_file description of the next page

GetPreviousURL (links_file)
Return to the previous document in links_file page URL

GetPreviousDescription (links_file)
The return of documents in links_file description of the previous page

GetNthURL (links_file, n)
Return the first n documents links_file the URL of the page

GetNthDescription (links_file, n)
Links_file return to document the first page of description of n

If the contents of the current page link is not a list of files, then:
GetListIndex return 0.
GetNextURL and return to the list of document GetNextDescription the last page of the URL and description.
GetPreviousURL and return to the list of document GetPreviousDescription the first page of the URL and description.
3. The use of Content Linking Component
Once you create a link to the content of their documents, the components can be added to the page. There is a typical example, which traverse the contents of the document links to all entries, and create a list page (hyperlink to that page).
<% 'In VBScript:
Set objNextLink = Server.CreateObject ( "MSWC.Nextlink")
%>

<UL>
<%
'get the number of entries in the menu file
intCount = objNextLink.GetListCount ( "contlink.txt")
'loop through the entries
For intLoop = 1 To intCount%>
<LI>
<A HREF = "<% = objNextLink.GetNthURL (" contlink.txt ", intLoop)%>">
<% = ObjNextLink.GetNthDescription ( "contlink.txt", intLoop)%>
</ A>
<%
Next
%>
</ UL>
This code first creates a Content Linking object. In the ordinary <UL> and </ UL> tags, the use of the Content Linking Object GetListCount method to find the link in the content of the number of entries in the list of documents. And then traverse these entries, an entry for each page into a <LI> tag, followed by a marked <A>. HREF attribute value from the list in document retrieval method using GetNthURL be used as link text description of the use of methods GetNthDescription.
Note that the contents of a list of documents and use it in the ASP page to be in the same folder. Otherwise, it should provide a relatively complete physical path or a virtual path, as follows:
inCount = objNextLink.GetListCount ( "links \ contlink.txt") 'physical path
inCount = objNextLink.GetListCount ( "/ demo / contlink.txt") 'virtual path


Asp Base Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.