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


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:

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
mypictureasp
<% 
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"

"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.

 

Tutorial home page