Active Server Pages: ASP file as a picture source
We are trying this tutorial to be simple, so in this page we will request imagenes from a ".asp" page, but the imagen will not  be newly generated. The images will be already saved in our server .

First, letīs check this two pages:
 
 

showpicture.html
<html>
<title>My picture</title>
<body>

<img src=mypicture.asp>

</body>
</html>

1
2
3
4
5
6
7
8
mypicture.asp
<% response.ContentType ="image/GIF" %>
<!--#include virtual="mypicture.gif" -->
1
2
  • 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
<html>
<title>My page</title>
<body>

<a href=adrotatorlink.asp><img src=mypicture.asp NOSAVE></a>

</body>
</html>

1
2
3
4
5
6
7
8
mypicture.asp
<% 
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" %>
     <!--#include virtual="picture1.gif" -->
 <% case 2 
     session("linkto")="http://linkto2.com" %>
     <!--#include virtual="picture2.gif" -->
<% case 3 
     session("linkto")="http://linkto3.com" %>
     <!--#include virtual="picture3.gif" -->
<% case 4 
     session("linkto")="http://linkto4.com" %>
     <!--#include virtual="picture4.gif" -->
<% case 5 
     session("linkto")="http://linkto5.com" %>
     <!--#include virtual="picture5.gif" -->
<% End select %>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
adrotatorlink.asp
response.redirect(session("linkto")) 1

"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.mysite.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.
NOTE:  By using "NOSAVE" code in our page, the client will no save the picture in the cache of the computer. It may be a problem for us: letīs suppose we have include this the same code in several pages within our site. Each time we visit a new page, session ("linkto") will be defined again, but in case the visitor clicks the back bottom of the browser and the picture show is the same one it was shown in our previous visit, when clicking the visitor will be redirect to a non-correct URL.


Google






   



MSN Nick Name



More Resources...





Most Viewed Services:
  1. HTML Tutorial
  2. XHTML Tutorial
  3. CSS Tutorial
  4. Javascript Tutorial
  5. DHTML Tutorial
  6. VB Script
  7. TCP/IP Tutorial
  8. ADO Tutorial
  9. MYSQL Tutorial
  10. ASP Tutorial
  11. AJAX Tutorial
  12. CFML Tutorial
  13. PHP Tutorial
  14. WML Tutorial
  15. FLASH Tutorial
  16. XML Tutorial
  17. RSS Tutorial
  18. SQL Tutorial
  19. HTML Articles
  1. Javascript Articles
  2. PHP Articles
  3. SEO Articles
  4. Web Design Articles
  5. SEO Tips
  6. Web Design Tips
  7. Articles
  8. CSS
  9. CSS Tips
  10. HTML Tips
  11. JAVASCRIPT Tips
  12. MYSQL Tips
  13. PHP Tips
  14. Money
  15. Tutorials
  16. Web Hosting



  • Home
  • Web Directory
  • Top Directoriers
  • Webmaster Directories
  • Contact
  • © Copyright 2006-2010 All Rights Reserved By CodeDcode.Com : HTML : RSS : TEXT : XML