Home

ASP ADVANCED

This chapter covers how to use two ActiveX components that are included with Active Server Pages.  In the first section, you learn how to use the Content Linking component.  This component can be used to make your site easier to navigate.  The second section presents a detailed example that illustrates how to use this component.  You learn how to use the Content Linking component to create a simple newsgroup.  Finally, in the third section, you learn how to use the Permission Checker component.  This component displays a link to a page only when the user has permission to access the page.

The Content Linking Component

The Content Linking component is useful in situations where you have a series of pages you need to link together.  For example, you can use this component to link the pages of an online book, a slide show, or even the messages in a newsgroup.  An example of how you can use this component to create a simple newsgroup is presented in the following section.

Normally, to link a series of pages, you need to insert a hypertext link in each page.  The Content Linking component simplifies this process.  Using this component, you can create a list of pages in a single file.  Once this file is created, you can use the methods of the component to display appropriate links in each page.

The Content Linking component has the following methods:

  • GetListCount (Content Linking List File)
    Returns the total number of pages contained in the Content Linking List file.
  • GetListIndex (Content Linking List File)
    Returns the position of the current page in the Content Linking List file.
  • GetNextDescription (Content Linking List File)
    Returns the description of the next page in the Content Linking List file.
  • GetNextURL (content Linking List File)
    Returns the path of the next page in the Content Linking List file.
  • GetNthDescription (Content Linking List File, Number)
    Returns the description for a page with a particular index in the Content Linking List file.
  • GetNthURL (content Linking List File, Number)
    Returns the path of the page with a particular index in the Content Linking List file.
  • GetPreviousDescription (Content Linking List File)
    Returns the description for the previous page in the Content Linking List file.
  • GetPreviousURL (Content Linking List File)
    Returns the path of the previous page in the Content Linking List file.

For example, suppose you want to create a step-by-step guide to cooking pasta on your Web site.  You want to devote a distinct Active Server Page to each step and display the steps in order.  The Content Linking component makes this easy to do.

First, you need to create a special file called the Content Linking List file.  The Content Linking List file is a normal text file that you can create with any text editor.  It simply contains a list of the pages you want to link.  Here's an example:

/pasta/grabpot.asp              Grab a pot from the cupboard.

/pasta/boilwater.asp            Boil some water in the pot.

/pasta/openbox.asp            Open box of pasta.

/pasta/dumpcontents.asp    Dump contents of box in pot.

/pasta/wait.asp                   wait ten minutes.

/pasta/home.asp                 Return to home page.

Once you create the Content Linking List file, you can save the file with any name.  For example, you could save the file as pasta. txt.

This sample file has two columns.  The first column contains a list of the files to link.  These can be Active Server Pages files or normal HTML files.  The second column contains descriptions of these files.  These two columns must be separated by a single tab character rather than spaces.  The Content Linking component won't be able to distinguish the two columns otherwise.

After you have created the Content Linking List file, you can use the Content Linking component to add navigational links to your Active Server Pages.  For example, you might want to display a list of all the steps involved in preparing pasta on the home page of your Web site.  You could do this with the following Active Server Page:

<HTML>
<HEAD><TITLE> Home Page </TITLE></HEAD>
<BODY>
<H2>Welcome To The Pasta Web Site!</H2>
<%
Set mylinks=Server.CreateObject("MSWC.NextLink")
%>
Here are the
<%=mylinks.GetListCount("pasta.txt") -1%>
steps for preparing pasta:
<OL>
<%
FOR i=1 TO mylinks.GetListCount("pasta.txt") -1
%>
<LI><A HREF="<%=mylinks.GetNthURL("pasta.txt",i)%>">
<%=mylinks.GetNthDescription("pasta.txt",i)%></A>
<%
NEXT
%>
</OL>
</BODY>
</HTML>

This Active Server Page displays a list of the links in the Content Linking List file. This is accomplished by creating an instance of the Content Linking Component.  An instance of this component is assigned to the variable named mylinks.

Three methods of the component are used:

  • First, the GetListCount( ) method retrieves a count of the number of entries in the Content Linking List file.  Whenever you call a method of the Content Linking component, you must pass the name of the Content Linking List file.  In this example, the method is called by using mylinks.GetListCount ("pasta.txt").

  • Second, the GetNthURL( ) method retrieves the n th URL entry in the Content Linking List file.  This method has two parameters.  The first parameter indicates the name of the Content Linking List file.  The second parameter indicates which entry to retrieve from this file.  For example, if you call GetNthURL("pasta.txt",2), the URL listed as the second entry in the pasta.txt file is returned.

  • Third, the GetNthDescription( ) method is called to retrieve the page descriptions from the Content Linking List file.  This method also takes two parameters.  The first parameter specifies the name of the Content Linking List file.  The second parameter indicates which entry to retrieve from this file.  For example, if you call GetNthDescription ("pasta.txt", 2), the description in the second entry in the pasta.txt file is returned.

The GetNthURL( ) and GetNthDescription( ) methods are used within a FOR...NEXT loop to display all the entries in the Content Linking List file.  All the entries are displayed except the final one.  This last entry is excluded because it points back to the home page.

In the preceding example, the methods of the Content Linking component are used to list a series of pages.  You can also use the methods of this component to link the individual pages together, as in the following example:

<HTML>
<HEAD><TITLE> step One </TITLE></HEAD>
<BODY>
<H1>Step 2: Boil Water </H1>
<H3>Boil some water in a pot.</H3>
<HR>
<%
Set mylinks=Server.CreateObject("MSWC.NextLink")
IF mylinks.GetListindex("pasta.txt")>1 THEN
%>
<A HREF="<%=mylinks.GetPreviousURL("pasta.txt")%>">
Previous Step</A>
<% END IF %>
<P>
<A HREF="<%=mylinks.GetNextURL("pasta.txt")%>">
Next Step</A>
</BODY>
</HTML>

Two methods of the Content Linking component are used in this Active Server Page.  The GetPreviousURL( ) method retrieves the path of the previous page.  The GetNextURL( ) method retrieves the path of the next page.  These methods create a link to the previous page and a link to the next page.

The GetPreviousURL( ) and GetNextURL( ) methods return different results depending on the current page. When these methods are called, the path of the current page is compared to the entries in the Content Linking List file.  The GetpreviousURL( ) method returns the entry that's above the entry for the current page.  The GetNextURL( ) method returns the entry that's below the entry for the current page.

If the current page isn't included in the Content Linking List file, the GetPreviousURL( ) method returns the first entry in the Content Linking List file.  The GetNextURL( ) method retrieves the last entry.