Download presentation
Presentation is loading. Please wait.
Published byCarmella Doyle Modified over 8 years ago
1
ASP (COMPONENTS) Active Server Pages (cont..) 1
2
global.asa file The Global.asa file is an optional file that can contain declarations of objects, variables, and methods that can be accessed by every page in an ASP application. All valid browser scripts (JavaScript, VBScript, JScript, PerlScript, etc.) can be used within Global.asa. The Global.asa file can contain only the following: Application events Session events declarations TypeLibrary declarations the #include directive Note: The Global.asa file must be stored in the root directory of the ASP application and each application can only have one Global.asa file. 2
3
ASP : Components 3 ASP Components are set of built-in- tools that automate common tasks such as displaying advertisements, keeping track of number of visitors etc. ASP components are created by using CreateObject method of Server object, ASP components are : 1.Ad Rotator is used to display banner advertisements on web pages. 2.Content Rotator – used to rotate HTML content on a page 3.Counter Component – used to store, increment or retrieve a value that persists for the lifetime of an application. 4.Page Counter – to keep track of number of visitors visited the web page 5.Permission Checker Component – used to check whether the user has permission to read or execute a particular file.
4
Ad Rotator Component 4 Used to display a series of different banner advertisements each time the Web page is viewed. Specifies how frequently different advertisements should be displayed. Also records the number of times an advertisement has been clicked by the user. The different files used by the Ad Rotator component are: Rotator Schedule File – a text ASCII file containing information about the images to be rotated. ASP File – the webpage that will display the advertisement along with other information. Redirection File – implements redirection and enables the Ad Rotator component to record how many users click on each advertisement.
5
Rotator Schedule File is an ASCII file that keep track of the images to be displayed, how frequently to be displayed, the advertiser’s URL where the user will be redirected when he clicks on the advertisement. This scheduler has 2 parts separated by a * sign :- – First part : it has 4 optional global parameters applicable to all advertisements. If no parameter is mentioned, the default value will be used. – Second part : It specifies file and location information for each individual advertisement and percentage of display time that each ad should receive. Properties: – Redirect : Redirect URL – specifies the URL of the file that implements the redirection. – Width : Width num – specifies the width of the ad in pixel, default value is 440 – Height : Height num – specifies pixel height, 60 is the default value – Border : Border num – specifies the thickness of the border around the ad in pixel. Default value is 1 5
6
Second section contains 4 lines: Line 1 – image of the file containing ad graphics Line 2 – URL of the web page to which user will redirect when the ad is clicked by the user Line 3 – Text description to be displayed Line 4 – Frequency with which the ad will be displayed. 6 REDIRECT redir.asp WIDTH 420 HEIGHT 50 BORDER 0 * homeloan.gif http://www.paisavasool.com All kinds of Home Loans 70 hawai.gif http://www.hotelsinhawai.com Visit All Hotels in Hawai 30 Adrotator.txt Home Page Welcome to our Web City <%Set myAd=Server.CreateObject(“MSWC.AdRotator”) Response.write(myAd.GetAdvertisement(“adrotator.txt”))%> An instance of Ad Rotator component is created using CreateObject() method of the server object and assigned to myAd variable using Set statement. GetAdvertisement() method of Ad Rotator is used to retrieve information about the ad to be displayed from the rotator schedule file sent as parameter. ASP file is needed to display the ads stored in the above rotator schedule file using the Ad Rotator component. Adhomepage.asp
7
7 ASP AdRotator Component The ASP AdRotator component creates an AdRotator object that displays a different image each time a user enters or refreshes a page. A text file includes information about the images. Note: The AdRotator does not work with Internet Information Server 7 (IIS7). Syntax
8
ASP AdRotator Example 8 The lines below the asterisk in the text file specifies the name of the images (ads) to be displayed, the hyperlink addresses, the alternate text (for the images), and the display rates (in percent). The first line in the text file above specifies what to happen when a visitor clicks on one of the images. The redirection page (banners.asp) will receive a query string with the URL to redirect to. Tip: To specify the height, width, and border of the image, you can insert the following lines under REDIRECT: REDIRECT banners.asp WIDTH 468 HEIGHT 60 BORDER 0 * w3s.gif... Assume that we have the following text file, named "ads.txt": REDIRECT banners.asp * w3s.gif http://www.w3schools.com Free Tutorials from W3Schools 50 xmlspy.gif http://www.altova.com XML Editor from Altova 50
9
Ad Rotator Properties: Border AdRotator.Border = size Specifies the thickness of the border around the advertisement in pixels. Clickable AdRotator.Clickable = value, value is true or false Specifies whether the ad should function as a hyperlink. TargetFrame AdRotator.TargetFrame = frame Specifies the name of frame into which the ad link should be loaded. 9
10
Content Rotator Component 10 The ASP Content Rotator component creates a Content Rotator object that displays a different content string each time a visitor enters or refreshes a page. A text file, called the Content Schedule File, includes the information about the content strings. The content strings can contain HTML tags so you can display any type of content that HTML can represent: text, images, colors, or hyperlinks. Syntax
11
11 Methods of Content Rotator ChooseContent ContRot.ChooseContent(schedule-path) Retrieves a HTML content string from the Content Schedule File randomly and displays on the current page. GetAllContent ContRot.GetAllContent(schedule-path) Retrieves all of the HTML content string from the Content Schedule File and write them directly to the web page as a list with tag after each entry.
12
12 ASP Content Rotator Example The following example displays a different content each time a visitor views the Web page. First, create a text file named "textads.txt" and place it in a subfolder called "text". "textads.txt": % #3 This is a great day!! % #3 % #4 Visit W3Schools.com Notice the #number at the beginning of each content string. This number is an optional parameter that indicates the relative weight of the HTML content string. In the text file above, the Content Rotator will display the first and second content string three-tenth of the time, and the third string four-tenths of the time.
13
13 Then, create an ASP file, and insert the following code: Example
14
14 ASP Source NOTE: Because the content strings are changed randomly in the text file, and this page has only four content strings to choose from, sometimes the page will display the same content strings twice in a row. Output This is a great day!! NOTE: Because the content strings are changed randomly in the text file, and this page has only four content strings to choose from, sometimes the page will display the same content strings twice in a row.
15
Counters Component 15 A counter is a persistent value that contains an integer. You can manipulate a counter with the Get, Increment, Set, and Remove methods of the Counters object. Once you create the counter, it persists until it is removed. Counters do not automatically increment on an event like a page hit. You must manually set or increment counters using the Set and Increment methods. Counters are not limited in scope. Once you create a counter, any page on your site can retrieve or manipulate its value. For example, if you increment and display a counter named hits in a page called Page1.asp, and you increment hits in another page called Page2.asp, both pages will increment the same counter. If you hit Page1.asp and increment hits to 34, hitting Page2.asp will increment hits to 35. The next time you hit Page1.asp, hits will increment to 36. All counters are stored in a single text file, Counter.txt. Only create one Counters object in your site. This single Counters object can create any number of individual counters.
16
16 Syntax: ASP Counters Component The Counters control is registered with the ProgId of "MSWC.Counters" Create the Counters object one time on your site by adding the following to the global.asa file: <OBJECT RUNAT=Server SCOPE=Application ID=Counter PROGID="MSWC.Counters"> Note: ASP Counter Properties - None
17
17 MethodsSyntaxDescription SetCounters.Set (CounterName, int) Where countername is the name of the counter and int specifies the new value for the countername. Sets the value of the counter to the specified value. If the counter does not exist it creates a new counter and sets its values. GetCounters.Get(CounterName) Where CounterName specifies the name of the counter Takes the name of the counter as parameter and returns the current value of the counter. IncrementCounters.Increment(CounterName)Increment the current counter value by 1 and returns the new value, if does not exist, then sets the value as 1. RemoveCounters.Remove(CounterName)Removes the counter from the Counter Object. ASP Counters Component Methods : Get, Set, Increment, Remove
18
Examples: ASP Counters Component Get Method Display the value of a counter with: Assign the value of the counter to a variable with: The following script displays the vote tally from a poll about favorite colors. <% If colornumber = "1" Then Counters.Increment("greencounter") ElseIf colornumber = "2" Then Counters.Increment("bluecounter") ElseIf colornumber = "0" Then Counters.Increment("redcounter") End If %> Current vote tally: red: green: blue: 18
19
19 Examples: ASP Counters Component Increment Method Increment the value of a counter with: Increment and display the value of a counter with: To retrieve the value of a counter, use Counters.Get. To set a counter to a specific value, use Counters.Set. The following code implements a one-line page-hit counter. There have been visits to this Web page. In this example, Counters.Increment increases the counter by one each time the client requests the page from the server.
20
20 Example: ASP Counters Component Remove Method The following code removes the counter hitscounter from the Counter.txt file. Example: ASP Counters Component Set Method The following code resets the hit counter pageHits to 0:
21
21 Examples: ASP Counters Component Opinion Poll <% vote = request.QueryString("Choice") if vote="Yes" then mycount.Increment("yesCounter") elseif vote="No" then mycount.Increment("NoCounter") elseif vote = "Cannot say" then mycount.Increment("yesNoCounter") end if %> Do you like Pizza Yes No Cannot say Input Type ="SUBMIT" value= "submit vote" Current Vote Tally Yes No Can not say this page has been visited times
22
Page Counter Component 22 Creates a counter which counts the number of times a page has been viewed, similar to Counters component, while Counters component is set manually, the page counter component is an automatic process. Syntax : Set myVar = Server.CreateObject(“MSWC.PageCounter”) Methods: Hits - myVar.Hits( [pathInfo]) – if the path Info is not specified, the hit count for the current page is displayed, i.e., number of times a specified Web page has been opened. PageHit – myVar.PageHit() – Increments the hit count for the current Web page by 1. Reset - myVar.Reset ( [pathInfo]) – Resets the hit count for a specified Web page to 0. Example : <% Set myPageCounter = Server.CreateObject(“MSWC.PageCounter”) myPageCounter.PageHit() Num= myPageCounter.Hits() %> This Page is visited
23
Permission Checker Component 23 Can be used to check whether the user has permission to access a particular file or not, this is possible by the password authentication protocols provided by Microsoft in its propriety Web Server – Internet Information Services (IIS). Syntax: Set myVar = Server.CreateObject(“MSWC.PermissionChecker”) Method: HasAccess – myVar.HasAccess (Path) – checks whether a user has permission to access a specified file and returns true or false.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.