ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program...

28
ASP

Transcript of ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program...

Page 1: ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.

ASP

Page 2: ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.

What is ASP?

• ASP stands for Active Server Pages • ASP is a Microsoft Technology • ASP is a program that runs inside IIS IIS stands

for Internet Information Services• PWS (Personal Web Server) is a smaller - but

fully functional - version of IIS• To run IIS you must have Windows NT 4.0 or later• To run PWS you must have Windows 95 or later

Page 3: ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.

ASP file

• An ASP file is just the same as an HTML file• An ASP file can contain text, HTML, XML, and

scripts• Scripts in an ASP file are executed on the

server• An ASP file has the file extension ".asp"

Page 4: ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.

What can ASP do for you?

• Dynamically edit, change, or add any content of a Web page

• Respond to user queries or data submitted from HTML forms

• Access any data or databases and return the results to a browser

• Customize a Web page to make it more useful for individual users

• Provide security - since ASP code cannot be viewed from the browser

• Clever ASP programming can minimize the network traffic

Page 5: ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.

IIS - Internet Information Server

• IIS is a set of Internet-based services for servers created by Microsoft for use with Microsoft Windows.

• IIS comes with Windows 2000, XP, Vista, and Windows 7. It is also available for Windows NT.

• IIS is easy to install and ideal for developing and testing web applications.

Page 6: ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.

How to Install IIS on Windows 7 and Windows Vista

Follow these steps to install IIS:• Open the Control Panel from the Start menu• Double-click Programs and Features• Click "Turn Windows features on or off" (a link

to the left)• Select the check box for Internet Information

Services (IIS), and click OK

Page 7: ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.

Test Your Web

• After you have installed IIS or PWS follow these steps:• Look for a new folder called Inetpub on your hard drive• Open the Inetpub folder, and find a folder named wwwroot• Create a new folder, like "MyWeb", under wwwroot• Write some ASP code and save the file as "test1.asp" in the

new folder• Make sure your Web server is running • Open your browser and type

"http://localhost/MyWeb/test1.asp", to view your first web page

Page 8: ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.

ASP Basic Syntax Rules

• An ASP file normally contains HTML tags, just like an HTML file.

• any ASP server script must be surrounded by the symbols <% … %>

Page 9: ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.

The response.write Command

<!DOCTYPE html><html><body><%response.write("Hello World!")%></body></html>

Page 10: ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.

ASP Variables

<!DOCTYPE html><html><body>

<%dim namename="Donald Duck"response.write("My name is: " & name)%>

</body></html>

Page 11: ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.

Procedures

A Sub procedure:• is a series of statements, enclosed by the Sub

and End Sub statements• can perform actions, but does not return a

value• can take arguments

Page 12: ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.

Procedures<!DOCTYPE html><html><head><%sub vbproc(num1,num2)response.write(num1*num2)end sub%></head><body>

<p>Result: <%call vbproc(3,4)%></p>

</body></html>

Page 13: ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.

Function Procedure

A Function procedure:• is a series of statements, enclosed by the Function

and End Function statements• can perform actions and can return a value• can take arguments that are passed to it by a

calling procedure• without arguments, must include an empty set of

parentheses ()• returns a value by assigning a value to its name

Page 14: ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.

Function<!DOCTYPE html><html><body>

<%Function myfunction()myfunction=Date()End Function

response.write("Today's date: ")response.write(myfunction())%>

<p>A Function procedure can return a result.</p>

</body></html>

Page 15: ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.

ASP OBJECTS

RESPONSE:• The ASP Response object is used to send output to the

user from the server.Property:• Buffer: response.Buffer[=Flag ]• False indicates no buffering. The server will send the

output as it is processed.• True indicates buffering. The server will not send output

until all of the scripts on the page have been processed, or until the Flush or End method has been called.

Page 16: ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.

Response

Methods:• Redirect: Redirects the user to a different URL• Write: Writes a specified string to the output• Clear: Clears any buffered HTML output• End: Stops processing a script, and returns the

current result• Flush: Sends buffered HTML output

immediately

Page 17: ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.

Response.clear<%response.Buffer=true%><html><body><p>This is some text I want to send to the user.</p><p>No, I changed my mind. I want to clear the text.</p><%response.Clear%></body></html>

Output:

(nothing)

Page 18: ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.

Response.End

<html><body><p>I am writing some text. This text will never be<%Response.End%>finished! It's too late to write more!</p></body></html>

Output:

I am writing some text. This text will never be

Page 19: ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.

Request Object

• The Request object is used to get information from a visitor.

Collections:• Form Contains all the form (input) values from a

form that uses the post method (POST Method)• QueryString Contains all the variable values in a

HTTP query string (GET Method)• ServerVariables Contains all the server variable

values

Page 20: ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.

ServerVariables

You can loop through all of the server variables like this:<%for each x in Request.ServerVariables response.write(x & "<br>")next%>

Page 21: ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.

ServerVariables<html><body><p><b>You are browsing this site with:</b><%Response.Write(Request.ServerVariables("http_user_agent"))%></p><p><b>Your IP address is:</b><%Response.Write(Request.ServerVariables("remote_addr"))%></p><p><b>The server's domain name:</b><%Response.Write(Request.ServerVariables("server_name"))%></p><p><b>The server's port:</b><%Response.Write(Request.ServerVariables("server_port"))%></p><p><b>The server's software:</b><%Response.Write(Request.ServerVariables("server_software"))%></p></body></html>

http://www.w3schools.com/asp/coll_servervariables.asp

Page 22: ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.

QueryString<!DOCTYPE html><html><body>

<form action="demo_simplereqquery.asp" method="get">First name: <input type="text" name="fname"><br>Last name: <input type="text" name="lname"><br><input type="submit" value="Submit"></form>

<%Response.Write(Request.QueryString)%>

</body></html>http://www.w3schools.com/asp/showasp.asp?filename=demo_simplereqquery

Page 23: ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.

QueryString<!DOCTYPE html><html><body><form action="demo_reqquery.asp" method="get">Your name: <input type="text" name="fname" size="20" /><input type="submit" value="Submit" /></form><%dim fnamefname=Request.QueryString("fname")If fname<>"" Then Response.Write("Hello " & fname & "!<br>") Response.Write("How are you today?")End If%></body></html>http://www.w3schools.com/asp/showasp.asp?filename=demo_reqquery

Page 24: ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.

Request.Form<!DOCTYPE html><html><body>

<form action="demo_form2.asp" method="post">First name:<input type="text" name="name" value="Donald" /><br>Last name:<input type="text" name="name" value="Duck" /><br><input type="submit" value="Submit" /></form><hr><p>The information received from the form above was:</p><%

If Request.Form("name")<>"" Then Response.Write("<p>") Response.Write("name=" & Request.Form("name")) Response.Write("</p><p>") Response.Write("The name property's count is: ") Response.Write(Request.Form("name").Count) Response.Write("</p><p>") Response.Write("First name=" & Request.Form("name")(1)) Response.Write("</p><p>") Response.Write("Last name=" & Request.Form("name")(2)) Response.Write("</p>") End if%></body></html>

Page 26: ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.

Cookies

• A cookie is often used to identify a user.• A cookie is a small file that the server embeds

on the user's computer. • It is a small piece of data sent from a website

and stored in a user's web browser while the user is browsing that website.

• Every time the user loads the website, the browser sends the cookie back to the server to notify the website of the user's previous activity

Page 27: ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.

Cookies

• With ASP, you can both create and retrieve cookie values.

• The "Response.Cookies" command is used to create cookies.

• The Response.Cookies command must appear BEFORE the <html> tag.

Page 28: ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.

Session

• A Session object stores information about, or change settings for a user session.

• Variables stored in a Session object hold information about one single user, and are available to all pages in one application.

• Common information stored in session variables are name, id, and preferences.

• The server creates a new Session object for each new user, and destroys the Session object when the session expires.