Asp Tutorial

Discussion in 'GR Classic Archive' started by MarkWLI, Oct 25, 2004.

  1. MarkWLI

    MarkWLI Guest

    Well, here is another ASP tutorial for the ages, and I haven't gotten a chance to do any javascript, but here is this one, it builds in a sense off the 'including pages in asp' tutorial.

    First, let´s check this two pages:

    showpicture.html
    Code:
    <html>
    <title>My picture</title>
    <body>
    
    <img src=mypicture.asp>
    
    </body>
    </html>
    mypicture.asp
    Code:
    <% response.ContentType ="image/GIF" %>
    
    * In the first file (showpicture.html) we have include in the html code the source for our picture ("mypicture.asp", instead of "mypicture.gif").
    * In the response page, first we have indicated whith kind of ContentType we are sending to the client (this time "image/GIF", and then by using "include/virtual" the file is send (in this case all files are in the same directory)

    Let´s try an examples:

    A rudimentary banner rotator system

    Our page is "mypage.html" and we are requesting a picture to a file named "mypicture.asp". This file will send to the client one of the pictures available (in this case up to 5), and two variables will be set up:

    * session ("ad"): will be used to save a number, which is needed to determinate which ad to show each time
    * session ("linkto"): will be used to save the link corresponding to the ad shown.

    mypage.html
    Code:
    <html>
    <title>My page</title>
    <body>
    
    [url="adrotatorlink.asp><img"][/url]
    
    </body>
    </html>
    mypicture.asp
    Code:
    <% 
    if session("ad")="" then 
         session("ad")=0
    end if
    
    if session("ad")=5 then 
       session("ad")=1 
    else 
        session("ad")=session("ad")+1 
    end if 
    
    response.ContentType ="image/GIF" 
    %> 
    
    <% Select Case session("ad") %>
    <% case 1 
         session("linkto")="http://linkto1.com" %>
         
     <% case 2 
         session("linkto")="http://linkto2.com" %>
         
    <% case 3 
         session("linkto")="http://linkto3.com" %>
         
    <% case 4 
         session("linkto")="http://linkto4.com" %>
         
    <% case 5 
         session("linkto")="http://linkto5.com" %>
         
    <% End select %>
    adrotatorlink.asp
    Code:
    response.redirect(session("linkto"))
    "mypage.html"

    At "mypage.html" we have include the regular HTML code to show a picture. We have used within the code the instruction "NOSAVE", so the picture will not be saved in the clients cache.


    "mypicture.asp"

    * Lines 2-3. Each time a new visitor gets to "http://www.myadrotator.com/adrotator.asp" a new session will be open, and by using the session method, we will define session("ad") value to 0. In case the visitor is not new, the value for session("ad") will exits, and that value will be keep.
    * Lines 6-10. The value for Session("ad") is increased by one unless that value is 5 (which is the maximum value allowed in this script)
    * Line 12. The ContentType is defined
    * Lines 15-31. By using Select_case and depending on the value saved in the instruction session("ad"), we will define session("linkto"), which will be the url to which we will redirect our visitor in case the picture send to the browser is clicked.

    "adrotatorlink.asp"

    After clicking the corresponding picture, and as we have already save the corresponding URL at session('linkto"), we will redirect the visitor to the correct URL.

    Enjoy!

    Please donate credits to the Mark ASP Tutorial Fund ;)
     
  2. MarkWLI

    MarkWLI Guest

    20+ views and no one replies?
     
  3. .Sly.

    .Sly. Well-Known Member

    Posts:
    136
    Likes Received:
    0
    Joined:
    Sep 21, 2004
    um well, its so good i dont no what it is! lol, i am no expert at this stuff and it might come in handy somtime, nice job it looks like alot of work.
     
  4. Llamaman

    Llamaman Senior Member

    Posts:
    2,059
    Likes Received:
    0
    Joined:
    Apr 24, 2004
    Location:
    UK
    If asp was more widely supported by webhosts then this would be quite a useful tutorial I think, and you would almost certainly get more comments. Might be worth trying it with http://1asphost.com for those wanting to try it out!
     
  5. MarkWLI

    MarkWLI Guest

    I guess, ASP is not as widely used as PHP but its much more secure, and exploits are less common, and eventhough it may be a couple milliseconds behind linux for load times only on some pages its still the #1 coding I would recommend for people to learn, there may be a lot of PHP guys now, but ASP is the way to go!
     

Share This Page