0% found this document useful (0 votes)
66 views21 pages

A Ctive S Erver P Age ASP

Active Server Pages (ASP) is a technology that allows web pages to be dynamic and interactive through server-side scripting. ASP pages have a .asp file extension and use script embedded between <% and %> tags that is executed on the server before the page is sent to the browser. Cookies can also be used to store and retrieve information about website visitors in ASP pages through the Request.Cookies and Response.Cookies objects.

Uploaded by

Tawfeek Yahia
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views21 pages

A Ctive S Erver P Age ASP

Active Server Pages (ASP) is a technology that allows web pages to be dynamic and interactive through server-side scripting. ASP pages have a .asp file extension and use script embedded between <% and %> tags that is executed on the server before the page is sent to the browser. Cookies can also be used to store and retrieve information about website visitors in ASP pages through the Request.Cookies and Response.Cookies objects.

Uploaded by

Tawfeek Yahia
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 21

Active Server Page

ASP
ASP
 Active Server Page (ASP) is a technology that enables
you to make dynamic and interactive pages.

 ASP pages have the extension .asp instead of .html

 ASP uses server-side scripting to dynamically produce


web pages that are not affected by the type of browser
the web site visitor is using.

 When a page with the extension .asp is requested by a


browser the web server knows to interpret any ASP
contained within the web page before sending the
HTML produced to the browser.
ASP
 All the ASP is running on the web server and no ASP
will ever be passed to the web browser.

 Any web pages containing ASP cannot be run by just


simply opening the page in a web browser. The page
must be requested through a web server that supports
ASP to interpret any ASP contained within the web page
,then sending the HTML produced to the browser.

 This is why ASP stands for Active Server Pages

 No server no active pages


Execution of an ASP.NET page
ASP
 As ASP was first introduced by Microsoft on its web
server. So it is the web server that ASP pages usually
run best on.

 When you run Windows and wish to play around


with ASP on your own system, you will need to
install Internet Information Services (IIS) that comes
free with Windows.

 IIS can act as a Personal Web Server (PWS)


How to run ASP on your own PC?
 You can run ASP on your own Pc without an external
server. To do that, you must install IIS on your PC.

 How to install IIS and run ASP on Windows XP


Professional?
 Insert the Windows XP Professional CD-Rom into your
CD-Rom Drive
 From the Start Button, go to Settings, and Control Panel.
 In the Control Panel window select Add/Remove
Programs.
 In the Add/Remove Programs window select Add/Remove
Windows Components.
 In the wizard window check Internet Information
Services, click OK.
 An Inetpub folder will be created on your hard drive.
 Open the Inetpup folder, and find a folder named wwwroot.
How to run ASP on your own PC?
 Create a new folder, like “MyWeb” under
wwwroot.
 Use a text editor to write some ASP code,
save the file as “test.asp” in the “MyWeb”
folder.
 Make sure that your Web Server is running-
its status can be checked by going into
Control Panel, then Administrative Tools, and
double- click the “IIS Manager” icon.
 To view your Asp page: Open your browser
and type in
http://localhost/MyWeb/test.asp
The Basic Syntax Rule
 An ASP file normally contains HTML tags, just
like an HTML file. However, an ASP file can also
contain Server Script between <% and %>

 Server Scripts are executed on the server, and can


contain any expressions, statements, procedures
or operators valid to the scripting language you
prefer to use.
ASP
 An ASP looks just like a normal HTML page (Text +
HTML tags) in addition to server side script.

 Ex.
<html>
<head>
<title> New page 1 </title>
</head>
<body>
<%......................%>
<h2> Hello
<%...........................%>
</body>
</html>
Write output to the browser
Ex.
<html>
<body>
<% response.write(“Hello World”) %>
</body>
</html>
Write output to the browser
 There is also a shorthand method for the
response.write command
 The following example also sends the text
Hello World to the browser
<html>
<body>
<%= “Hello World” %>
</body>
</html>
Note That:
 You can use several scripting language in ASP.
However, the default scripting language is
VBScript. Just insert the :
<%@ language = “language” %>
above the <html> tag in order to using another
script language than default.

 Because the scripts are executed on the server,


the browser that displays the ASP file does not
need to support scripting at all.
Ex.
<%@ language = “javascript” %>
<html>
<head>
<% function aa(n1,n2)
{
alert (n1*n2)
}
%>
</head>
<body>
<p> Result: <% aa(2,3) %> </p>
</body>
</html>
ASP
 An Active Server Page is a web page that includes
program code that is processed on a Microsoft web
server before the page is sent to the user.

 Active Server Pages (ASP) is a server side scripting


language that lets a webmaster transform the plain,
static web site into dynamic solution. With
Microsoft's server side scripting language you can
gather data from your site's visitors, use sessions,
cookies, application variables, and more.
COOKIES
 To identify a user, a cookie is often used
 A cookie is a small text file that is stored on client
machine that is embedded by the server. Each time
the same computer requests a page with a browser, it
will send the cookie too.
 You can both create and retrieve cookie values in
ASP.
To store information specific to a visitor of your
website, ASP Cookies are used.
You can set the expiration date of the cookie for some
day in the future it will remain their until that day
unless manually deleted by the user
How to Create a Cookie

 To create cookies, the "Response.Cookies" command


is used .
 BEFORE the <html> tag, the Response.Cookies
command must appear
 We create an welcome cookie in the example below
 In the example below, we will create a cookie named
"CountVisitors" and assign the value numvisits to it
EX.
<%
dim numvisits
response.cookies("CountVisitors").Expires=date+365
numvisits=request.cookies("CountVisitors“)
if numvisits="" then
response.cookies("CountVisitors")=1
response.write("Welcome! This is the first time you are visiting this Web
page”)
else
response.cookies("CountVisitors")=numvisits+1
response.write("You have visited this Web page " & numvisits”)
if numvisits=1 then
response.write " time before!"
else
response.write " times before!"
end if
end if
> <%html> <body> </body> </html>
How to Retrieve a Cookie Value?
 To retrieve a cookie value, the
"Request.Cookies" command is used.
 In the example below, we retrieve the value of
the cookie named "goodname" and display it
on a page.
EX.
<%
gname=Request.Cookies("goodname”(
response.write("Goodname=" & gname(
%>
A Cookie with Keys
 We say that the cookie has Keys if a cookie
contains a collection of multiple values.

 In the example below, we will create a cookie


collection named "visitor"

 The "visitor" cookie has Keys that contains


information about a user:
.EX
<%
Response.Cookies("visitor")("firstname")="Ahmed"
Response.Cookies("visitor")("lastname")= "Ali"
Response.Cookies("visitor")("country")= "Egypt"
Response.Cookies("visitor")("age")="25"
%>

You might also like