In previous lessons we have used response object to send output to web browser.
Response.write "<html><body>Hello World!</body></html>"
In this lesson we will cover more methods and usages of response object.
Sometimes you want to redirect users arriving at a page to another URL. This is easily possible with ASP. We will use "redirect" method of response object for this purpose.
For example lets assume you want to send different people to different pages according their login information. In this case you can use redirection.
In our first example we will assume that we have two groups of people who will login to our system, students and
For ease of programming we will assume user names starting with the letter "s" are students and usernames starting with the letter "t" are teachers.
Again we will consider the word "student" as default password of students and "teacher" as default password for
<form action="login.asp" method="post">
User Name: <input type="text" name="username"><br>
Password: <input type="password" name="pass"><br>
<input type="submit" value="Enter">
if left(username,1)="s" and pass="student" then
if left(username,1)="t" and pass="teacher" then
<center><h2>You have logged in Students section of website
<center><h2>You have logged in Teachers section of website
Your login information is not correct!<br>
Wither click <a href="login.html">here</a> to return to
Or click <a href="register.html"> here</a> to go to
Please send your requests for registration<br>
to our administration email box.
Before we end this section, let me warn you that pages that redirect users to another page must do this redirection before sending anything to user's browser. This means page cannot contain html codes etc. before redirection code.
Proxy servers and caching
Many of Internet service providers use cache and proxy servers to increase their performance and security. When
someone browse main page of yahoo website, it can be retrieved from your website, Temporary cache of browser or ISP proxy server or cache.
This will improve performance, as it is not needed to use expensive Internet bandwidth for retrieving the same page for hundreds of times everyday. After retrieving a static page for the first time proxy server and browser cache will deliver cached copy instead of downloading a fresh copy. Internet bandwidth is expensive in most parts of the world yet.
However sometimes we need to avoid caching a page. For example if you have a dynamic page such as a web email box you will want to avoid caching pages. Otherwise new users will see pages retrieved by other users instead of fresh copies, which belong to their own web mail account.
In fact users will see a constant page instead of dynamic pages created at server. To avoid caching a page in browser, you must modify header of asp page.
You can determine the expiration time for each page in seconds.
Example 7-2: expire.asp
This page is expired immediately.
Discussed method works on a web browser only. This will not control how they are cached in proxy servers.
If you want to avoid caching a page in proxy servers you must use "cachecontrol" property of "response" object.
Example 7-3 public.asp
This page will not be cached in proxy server
If you put the code on a remote server over the Internet and browse it behind a proxy server you will see that it will refresh with new counter value each time you visit the page.
In previous lessons we used form and querystring methods of retrieving form data sent by browser. In this lesson we will introduce other methods and properties of request method.
When we use a browser to request a page from server, a lot of information is sent to server along with page filename.
As an example, we can mention browser and operating system types. This information is stored in "Server Variables".
In addition to browser information some other variables related to server itself are stored in server variables.
Application physical path and running script name are among the server variables, which are accessible by asp program.
We can read the value of each server variable using "ServerVariable" method of the request object.
Here we have written an example to extract the value of HTTP_REFERER server variable and copy it to "referrer"
When someone clicks on a link on the Internet to visit your page, this variable holds address of the page, which has sent the user to our page. If you want to track websites that send you traffic you can see the value in this
If you want to know IP address of the client computer (which browser is running on it) then you can use this server variable.
<head><title>Referer and IP address</title></head>
You are coming here by clicking on the page:
Your current IP address is
In this lesson we tried to cover remaining important methods and properties of response object. We also studied a new and important method of request object.
1- Create a html login page with the filename "login.html" login.asp is another file which will process data submitted by login.html
login.asp will store username in a session variable and will contain a main menu.
Menu must include a logout link which points to a logout.asp file. This file will clear the username session variable and will contain a link to login page. Prepare html and asp files for described application.
2- We have 3 affiliate web sites which have put a link on their web sites to send visitors to our site. They have put the links on these pages.
Create three counter variables, One for each web site. Create an asp file to show results of our affiliate program. (number of visitors coming from other sites)
Return to Index Page