ASP components,
The server object
The server-object gives access to methods and properties of the server. Most of this methods and properties act as functions.
Server.properties|method
Properties
ScriptTimeout Number of seconds a script can run before the timeout is reached. Methods
CreateObject Makes a server-object. HTML Encode This command translate characters in HTML-Code.
Example:
<%= server.HTMLEncode("The tag= <P>") %>
The result is :The tag= <P>
MapPath Adds a virtual path(absolute path on the server or relative path from the page) to the physical path. URLEncode Adds rules for URL-encoding on the selected characters. To create a instance of a object
Server.CreateObject(object type)
Object type: The type of object that is being created. [provider.]Component[.version]
Objects that are created with
Server.CreateObject
have a page-range. They are automatic destroyed when the page is completed.If you want to create a object with a session-range or application-range, you can add the tag
<OBJECT>
and set the attributeSCOPE
toSESSION
orAPPLICATION
. You can also store the object as a session-variable or application-variable.A object that is stored in a session-variable, is destroyed when the session object is destroyed; Time-out or when
ABANDON
is used.
<% Set session("adv")=Server.CreateObject("MSWC.AdRotator") %>
You can also destroy a object by setting the variable to
NOTHING
or a new value.
<% Session("adv")=Nothing %gt;
<% Session("adv")="another_value" %gt;You cannot create a objectexample with the same name as the object. The next line will create a fault.
<% Set Response = Server.CreateObject("Response") %>
The component Ad Rotator
This makes a AdRotator-object that automatic rotates the ads on a page. Each time a page is accessed (or reloaded) the Ad Rotator-component shows a new ad based on the data in the file.
You can count howmany visitors click on the add, by setting the URL-parameter to a redirect file.
Redirect file
This is a file that makes it possible to count howmany visitors click on the ad. You can add script in this file, so this data can be stored in a database.
Example:
---ADREDIR.ASP---
<% Response.Redirect(Request.QueryString("url")) %>Rotation-file
A text-document that holds the data for the ad rotation.
This file exists of 2 sections. In the first section the parameters of the rotation schedule are stored. In the second the file-data and place are stored. The two sections are separated by a line with a *
Looks like
[REDIRECT url]
[WIDTH width]
[HEIGHT height]
[BORDER border]
*
advURL
URLintropageAdv
Text
value
URL The path to the DLL or ASP redirect-file. Can be complete (http://Myserver/mydir/redirect.asp) or virtual(/mydir/redirect.asp) width The width of the ad in pixels. Standard is 440 pixels. height The height of the ad in pixels. Standard is 60 pixels. border The width of the hyperlink-border around the ad, in pixels. Standard is 1 pixel, add 0 if you don't want a border. advURL The location of the image-file of the ad URLintropageAdv The location of the advertisers page. If there is no page, add - to indicate there is no page. text This is the alternative text that is shown when the browsers does not show pictures. value A number between 0 and 4 294 967 295 that indicates the relative weight of the ad. If there are 3 ads in the rotation-file with the values 2, 3 and 5. The first ad is shown 20%, the second 30% and the third 50% of the time. Example:
---ADrot.txt--- redirect adredir.asp width 500 height 60 * ../pics/ad1.jpg http://www.ad1.com the first add 1 ../pics/ad2.gif http://www.ad2.com the second add 1 ../pics/ad3.jpg http://www.ad3.com the third add 2 ../pics/ad4.gif http://www.ad4.com the fourth add 3Creating a Ad rotator object.
Set adrotatorname = Server.CreateObject("MSWC.AdRotator").
Properties
Methods
Border Thickness of the border around the ad. Clickable If the ad is clickable or not TargetFrame The name of the frame where the add shown.
GetAdvertisement Gets the specifications of the next ad and makes the HTML-code.
<HTML> <HEAD> <TITLE>Example banner</TITLE> <META http-equiv="refresh" conetent="5"> </HEAD> <BODY> <% dim varAd, objAd set objAd=Server.Createobject("MSWC.AdRotator") objad.Border=2 objad.targetframe="target=rest" varAD=objAd.getadvertisement("Adrot.txt") %> <CENTER><% =varAD %></CENTER> </BODY> </HTML>The next HTML-code is ignored by GetAdvertisement and added to the end of the page, so the next ad is shown;.
<A HREF="http://www.mysite.com/adredir.asp?http://www.anothersite.com"> <IMG SRC="pics/banner.jpg" ALT="explanation" WIDTH=500 HEIGHT=60 BORDER=2></A>The page is automatic refreshed every 5 seconds. Usually the banner is added is a separated frame.
Content linker
The content linker is used to create a product-tour or a tutorial. The user can go to the next/previous page, begin and end page. You can also generate a content table.
The content linker gets its information from a list, this list holds all the webpages and there sequence.
Structure of a content linking list
URL-webpage [explanation [comment]]
URL-webpage The URL of the page explanation This information can be used with GetPreviousDescription, GetNextDescription and GetNthDescription. comment More information that is not used by the component. Example (producttour.txt)
product1.asp product1 product1_explanation product2.asp product2 product2_explanation product3.asp product3 product3_explanation product4.asp product4 product4_explanation product5.asp product5 product5_explanationThey are separated by tabs
The use of content linking
Set NextLinkName = Server.CreateObject("MSWC.NextLink")
Methods
GetListCount Counts the number of items listed. GetNextURL Gets the next page in the Content linking list. GetPreviousDescription Gets the description of the previous page. GetListIndex Get the index of the present page in the list. GetNthDescription Gets the description of the Nth page in the list. GetPreviousURL Gets the URL of the URL of the previous page in the list. GetNextDescription Gets the description of the next page in the list. GetNthURL Gets the URL of the Nth page in the list. Example of content list:
<HTML> <HEAD><TITLE>Tour of products</TITLE></HEAD> <BODY> <form> Tour products table of content.</P> <P> <% dim teller,purl,pdesc,objNl,listindex,listcount,pfirst,pend set objNL=server.createobject("MSWC.NextLink") listindex=objNL.GetListIndex("producttour.txt") listcount=objNL.GetListCount("producttour.txt") pFirst=objNL.GetNthURL("producttour.txt",1) pEnd=objNL.GetNthURL("producttour.txt",listcount) for teller=1 to listcount purl=objNL.getNthurl("producttour.txt",teller) pdesc=objNL.getNthdescription("producttour.txt",teller) %> <A HREF="<% =purl%> < =pdesc %></A><P> <% Next %< <input type=button value=Home onClick="location.href='<% =pFirst %>'"><P> <input type=button value=End onClick"location.href='<% =pEnd %>'"> </form> </body> </html>With the following script the buttons for next, previous, first and last are added in every page.
<% dim pNext,pPrev,objNL,dNext,dPrev,listindex,listcount,pFirst,pEnd set objNL=server.createobject("MSWC.NextLink") pPrev=objNL.GetPreviousURL("producttour.txt") pNext=objNL.GetNextURL("producttour.txt") dNext=objNL.GetNextDescription("producttour.txt") listindex=objNL.GetListIndex("producttour.txt") listcount=objNL.GetListCount("producttour.txt") pFirst=objNL.GetNthURL("producttour.txt",1) pENd=objNL.GetNthURL("producttour.txt",listcount) %> <% if listindex > 1 then%> <input type=button value='<% =dPrev %>' onClick="location.href='<%=pPrev %>'"> <% end if %> <% if listindex <> listcount then%> <input type=button value='<% =dNext %>' onClick="location.href='<%=pNext %>'"> <% end if %> <input type=button value=home onClick="location.href='< =pFirst %>'"> <input type=button value=end onClick="location.href='< =pEnd %>'"> <input type=button value=TOC onClick="location.href='toc.asp'">
Browser capabilities
It is handy to know which browser is requesting the page. Some browser can't work with frames, or sound files, ...
The component browser capabilities makes a BrowserType-object that can be used to show the browser capabilities.
When a browser connects to webserver it automatic send a HTTP-header. This header is ASCII with the identification of the browser and version number. The browserType-object compares this data with the data in Browscap.ini
If a match is found, BrowserType-object gets the properties of the browser.
If the object can't find a match, the standard is used. If there is no standard browser in Browscap.ini, all the properties get UNKNOWN as value.
You can update Browscap.ini. You can download the latest version from the Microsoft-site or from www.cyscape.com
Set BrowserType = Server.CreateObject("MSWC.BrowserType")
<% @language=vbscript %> <HTML> <HEAD><TITLE>c32.asp<>/TITLE></HEAD> <BODY> <% Set bc = Server.CreateObject("MSWC.BrowserType") %> Browser Name: <%=bc.browser %><p> Browser Version: <%=bc.version %><p> <% if (bc.frames = TRUE) then %> I noticed you do frames<p> <% else %> I noticed you are frame challenged<p> <% end if %> <% if (bc.tables=TRUE) then %> I noticed you do tables<p> <% else %> I noticed you can't do tables<p> <% end if %> <% if (bc.BackgroundSounds=TRUE) then %> I noticed you allow me to play music<p> <% else %> I noticed you aren't a music listener<p> <% end if %> <% if (bc.vbscript=TRUE) then %> I noticed you are VBscript capable<p> <% else %> I noticed you can't understand VB Script<p> <% end if %> <% if (bc.javascript=TRUE) then %> I noticed you understand JScript<p> <% else %> I noticed you don't understand JScript<p> <% end if set bc=nothing %> </BODY> </HTML>