INTRODUCTION
ASP stands for Active Server Pages ASP is a program that runs inside IIS (Internet Information Services) An ASP file can contain text, HTML, XML, and scripts Scripts in an ASP file are executed on the server When a browser requests an ASP file, IIS passes the request to the ASP engine. The ASP engine reads the ASP file, line by line, and executes the scripts in the file. Finally, the ASP file is returned to the browser as plain HTML
You can run ASP on your own PC without an external server. To do that, you must install Microsoft's Personal Web Server (PWS) or Internet Information Services (IIS) on your PC. The default scripting language is VBScript. To set JavaScript as the default scripting language for a particular page you must insert a language specification at the top of the page. Like this: <%@ language="JavaScript"%> Advantages of ASP: • Minimizes network traffic by limiting the need for the browser and server to talk to each other • Makes for quicker loading time since HTML pages are only downloaded • Allows to run programs in languages that are not supported by the browser • Can provide the client with data that does not reside on the client’s machine • Provides improved security measures since the script cannot be viewed by the browser Difference between server side scripting and client side scripting: Scripts executed only by the browser without contacting the server is called client-side script. It is browser dependent. The scripting code is visible to the user and hence not secure. Scripts executed by the web server and processed by the server is called server-side script. Order of execution for an ASP application: 1) Global.asa 2) Server-side Includes statements 3) Directives 4) Jscript scripts tagged within <% Response.write("3
") %> OUTPUT: 2 4 <%@language="JScript"%> <% Response.Write("3
"); %>
3
1
5
OUTPUT: 1
5
3
2
4
ASP PROCEDURES Call a procedure using vbscript: <% sub vbproc(num1,num2) response.write(num1*num2) end sub %> <%call vbproc(3,4)%> OR <%vbproc 3,4%> Call a procedure using javascript: <%@ language="javascript" %> <% function jsproc(num1,num2) { Response.Write(num1*num2) } %> <%jsproc(3,4)%> Call both vbscript and javascript procedures in vbscript: <% sub vbproc(num1,num2) Response.Write(num1*num2) end sub %> <%call vbproc(3,4)%> <%call jsproc(3,4)%>
Note: When calling a JavaScript or a VBScript procedure from an ASP file written in JavaScript, always use parentheses after the procedure name. In vbscript, parentheses are optional. If you omit the "call" keyword, the parameter list must not be enclosed in parentheses. ASP FORMS and INPUTS Commands for information retrieval from forms: 1. Request.QueryString 2. Request.Form Difference between GET and POST methods: GET: 1. Limited data can be sent upto 255 characters. 2. Command used is Request.QueryString 3. Data is visible to the users. POST: 1. Umlimited data can be sent. 2. Command used is Request.Form 3. Data is not visible to the users. ASP COOKIES A cookie is a temporary file used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. Why is a cookie used? A cookie (persistent) enables a website to remember you on subsequent visits, speeding up or enhancing your experience of services or functions offered. For example, a website may offer its contents in different languages. On your first visit, you may choose to have the content delivered in French and the site may record that preference in a persistent cookie set on your browser. When you revisit that site it will use the cookie to ensure that the content is delivered in French. Creating a Cookie: <%Response.Cookies("firstname")="Alex"%>
Properties: 1. Domain: This is the domain that the cookie originated from. It is set by default to the domain in which it was created but it can be altered. Example: Response.Cookies("name").Domain = "www.cookiemonster.com" 2. Expires: There are 2 ways. a) You can use the current date and add or subtract days Response.Cookies("name").Expires = Date + 365
b)
You can set it to a specific date
Response.Cookies("name").Expires = #May 10,2002# Note: To expire the session enabled with cookies, Give current date. Example: Response.Cookies("name").Expires = Date OR Date-1 3. Path: This specifies in more detail the exact path on the domain that can use the cookie. Response.Cookies("name").Path = "/this/is/the/path" 4. Secure: If set, the cookie will only be set if the browser is using secure sockets or https:// to connect. Response.Cookies("name").Secure = True Dictionary Cookie OR Cookies with Keys: It is a cookie that can hold multiple values. Example: Response.Cookies("name")("first") = "John" Response.Cookies("name")("last") = "Smith" How to know if the cookie has keys? Ans: With the Haskeys property. Example: <% dim x,y for each x in Request.Cookies response.write("
") if Request.Cookies(x).HasKeys then
for each y in Request.Cookies(x) response.write(x & ":" & y & "=" & Request.Cookies(x)(y)) response.write("
") next else Response.Write(x & "=" & Request.Cookies(x) & "
") end if response.write "
" next %> Note: There are limits on how much data you can put on a clients browser. Most browsers allow you to place 20 cookies per domain at a maximum of 4k each. Types of cookies: 1. Persistent: Persistent cookies are stored on your computer hard disk. They stay on your hard disk and can be accessed by web servers until they are deleted or have expired. Persistent cookies are not affected by your browser setting that deletes temporary files when you close your browser. 2. Non-Persistent: Non-persistent cookies are saved only while your web browser is running. They can be used by a web server only until you close your browser. They are not saved on your disk.
ASP OBJECTS
Response Object: Response object is used to display items on a web page. Request Object: The ASP Request object is used to get information from the user. Application Object: A group of ASP files that work together to perform some purpose is called an application. The Application object in ASP is used to tie these files together. Session Object: The Session object is used to store information about, or change settings for a user session. Server Object: The ASP Server object is used to access properties and methods on the server.
ASPError Object: The ASPError object is used to display detailed information of any error that occurs in scripts in an ASP page. Object Context: The ObjectContext object can be used to commit or abort a transaction. Collections, Properties and Methods: OBJECT COLLECTIONS PROPERTIES 1. Cookies 1. Buffer Response 2. ContentType 3. Expires 4. ExpiresAbsolute 5. Charset 6. CacheControl 7.IsClientConnected 8. Pics 9. Status 1. Cookies 1. TotalBytes Request 2. Form 3. QueryString 4.ServerVariables 5.ClientCertificate Application 1. Contents 2. StaticObjects
METHODS 1. Write 2. Redirect 3. End 4. Clear 5. Flush 6. BinaryWrite 7. AddHeader 8.AppendToLog 1. BinaryRead
EVENTS
Session
1. Contents 2. StaticObjects
Server
1. CodePage 2. LCID 3. SessionID 4. Timeout 1. ScriptTimeOut
1. Lock 2. UnLock 3.Contents.Remove 4.Contents.RemoveAll() 1. Abandon 2. Contents.Remove 3.Contents.RemoveAll() 1. CreateObject 2. Execute 3. GetLastError() 4. Transfer 5. HTMLEncode 6. URLEncode 7. MapPath
1. Application_OnStart 2. Application_OnEnd 1. Session_OnStart 2. Session_OnEnd
Error
1. ASPCode 2. ASPDescription 3. Category 4. Column 5. Line 6. Source 7. Description 8. File 9. Number
Object Context
1. SetAbort 2. SetComplete
1.OnTransactionAbort 2.OnTransaction CommitEvent
RESPONSE: Collections Collection Cookies Description Sets a cookie value. If the cookie does not exist, it will be created, and take the value that is specified
Properties Property Buffer CacheControl Charset ContentType Expires ExpiresAbsolute IsClientConnected Pics Status Methods Method AddHeader AppendToLog BinaryWrite Clear End Flush Redirect Write REQUEST: Description Adds a new HTTP header and a value to the HTTP response Adds a string to the end of the server log entry Writes data directly to the output without any character conversion Clears any buffered HTML output Stops processing a script, and returns the current result Sends buffered HTML output immediately Redirects the user to a different URL Writes a specified string to the output Description Specifies whether to buffer the page output or not Sets whether a proxy server can cache the output generated by ASP or not Appends the name of a character-set to the content-type header in the Response object Sets the HTTP content type for the Response object Sets how long (in minutes) a page will be cached on a browser before it expires Sets a date and time when a page cached on a browser will expire Indicates if the client has disconnected from the server Appends a value to the PICS label response header Specifies the value of the status line returned by the server
Collections Collection ClientCertificate Cookies Form QueryString ServerVariables Properties Property TotalBytes Description Returns the total number of bytes the client sent in the body of the request Description Contains all the field values stored in the client certificate Contains all the cookie values sent in a HTTP request Contains all the form (input) values from a form that uses the post method Contains all the variable values in a HTTP query string Contains all the server variable values
Methods Method BinaryRead Description Retrieves the data sent to the server from the client as part of a post request and stores it in a safe array
APPLICATION: Collections Collection Contents StaticObjects Description Contains all the items appended to the application through a script command Contains all the objects appended to the application with the HTML