Software Notes by softsys

Search   Chat 


Active Server Pages
=> What are Active Server Pages ( ASPs ) ?

ASP is a server side technology developed by Microsoft to develop dynamic, interactive, high-
performance Web Server Applications.

ASP is not a language. Rather it makes use of scripting languages like JScript, VBScript.

ASP is also no an application (like the conventional applications FrontPage, Word)

ASP is a technology that allows for the programmatic ( dynamic ) construction of HTML pages just
before they are delivered to the user. That is, with ASP we can write a set of instructions that
can be used to generate HTML just after the web page has been requested by a client, and just
before it is delivered.

ASP page is an extended HTML page ( may contain CSS and client side scripts ), that has been
extended with
1] Server Side scripts
2] Objects
3] Components.
This makes it possible to create Web Sites with dynamic content.

=====================================================

=> What can you do with Active Server Pages ?

Some of the very simple jobs that can be done,

Retrieve information entered into an HTML form and store that information in database.

Carry out different searches.

Create personalised Web Pages that display different content to different users.

Add hit counters to one or more pages of Web site.

Track information about user activity at your Web site and save information in a custom log file.

=======================================================

=> What is needed to run ASP ?


1] In order to write an ASP one of the following options is available
(a) Notepad
(b) Microsoft Visual Interdev
(c) Microsoft FrontPage

2] In order to publish ( execute ), Web Server ( i.e. the software ) that supports ASPs is
needed.

3] A web browser to view and test the pages. Since ASP is server side technology, the version or
make of the browser is insignificant.

( When browsing pages on the Internet or local intranet, the browser and Web Server software are
generally hosted on two different machines , client machine and server machines respectively.
But while developing the site , i.e. in development environment , its possible that the
server s/w, browser and the editor software are installed on the same machine. In this case
same single machine acts as server and client. )

=======================================================

=> Different Servers that support ASP?

1] Operating System: Windows 2000
Server Software: IIS ( Internet Information Server ) 5.0
Supports: ASP 3.0

2] Operating System: Windows NT 4.0
Server Software: IIS ( Internet Information Server ) 4.0
Supports: ASP 2.0

3] Operating System: Windows Workstation / Windows 98 / Windows 95
Server Software: PWS ( Personal Web Server )
Supports: ASP 2.0

4] Some of the other Web Servers which can also be installed on Operating system other than
Microsoft Windows are,
->Apache Web Server
->Netscape's Web Server

These do not have an in-built support for ASP. But these can be extended to support ASP
by installing third party softwares. one such softwarte is "Chili!Soft" which can be
installed as an ad-on to Apache & Netscape so that ASP can be supported.

=======================================================

=> How does the Web server work ? How are Active Server Pages served ?

All Web servers, fundamentally work in similar fashion, and their main function is to serve
pages. IIS is no different from other Web servers in this respect. Initially IIS (or any
other Web Server ) was developed to serve only HTML or static pages. When someone requested
a Web page from a Web Site using IIS, the server would fetch a static HTML file from disk or
memory and send it out to the person's browser. The primary resposibility of IIS was an
efficient interface between browsers and a bunch of files stored on Web server's hard disk.

The process described above can get much more complicated, but can be broadly described in
following steps:

1] User enters the Internet address of an HTML file into the address bar of a Web browser
and presses enter to request a Web page.
e.g. http://www.asp-site/hello.htm

2] The browser sends request for the Web Page to a Web Server such as IIS.

3] The Web server receives the request and recognizes that the request is for an HTML file
because the requested file has the extension .htm or .html

4] The Web server retrieves the proper HTML file from disk or memory and sends file back to
the browser.

5] The HTML file is interpretted by the person's Web browser and the results are displayed
in the browser window.


While serving ASPs the above procedure differs. This is because ASP allows IIS to server
dynamic pages as well ( IIS can still be used to serve static HTML pages ). Using ASP,
pages with new content can be created in response to user requests.

The process can be described in following steps:

1] User enters the Internet address of an HTML file into the address bar of a Web browser
and presses enter to request a Web page that can also be an ASP page.
e.g. http://www.asp-site/hello.asp

2] The browser sends request for the Web Page to a Web Server such as IIS.

3] The Web server receives the request and recognizes the request by the extension of the
page being request. If the extension is .asp it is recognized as ASP page

4] The Web server retrieves the proper ASP file from disk or memory.

5] The Web server sends the file to special program named "asp.dll". It is located on the
same machine as the Web Server Software.

6] The ASP file is processed from top to bottom and any encountered commands are executed.
The result of this process is a standard HTML file which is sent back to the Web server.

7] The generated HTML file is sent back to the browser.

8] The HTML file is interpretted by the person's Web browser and the results are displayed
in the browser window.


Important Issues to consider:

1] When an ASP page is executed, first all the server code is interpretted and converted
to HTML.

2] asp.dll when executing the .asp file checks the scripting language - VBScript or JScript
and accordingly gives call to the particular engine.
3] The Web Server checks the extension of file while deciding the type of file - html or
asp.
- So if the file with extension ".htm" contains ASP code will result into an error, as it
will be sent as it is to the browser.
- Similarly if pure HTML file is given extension .asp, will be unnecessarily checked for
ASP code, make it inefficient.
4] Caching: An ASP page may not be interpretted every time it is requested. If the same page
has been previously requested, the page will be retrieved from the cache. Actualy Web
Server maintains cache of HTML results of previously requested ASP pages, for saving time
when returning result of request ASP page.
5] An ASP page from the perspective of Server and Client:

From the perspective of WEB server, an ASP page is very different from a normal HTML page.
A normal HTML page is sent without processing to browser. All the commands in an ASP, on
the other hand, must first be executed to create an HTML page. This allows ASP page to be
dynamic.

From the perspective of browser, on the other hand, an ASP page is no different from a
normal HTML page. The only difference being the extension of file being requested.
Against the request, browser always receives a normal HTML page. This allows an ASP
page to be compatible with all browsers.

========================================

=> Integrating Scripts into Active Server Pages:

An ASP page is primarily a scripting environment. It is possible to integrate scripts created
with both JScript and VBScript into an ASP page. Any other scripting language like Perl can
also be used with ASP. Any scripting language that has a scripting engine compatible with
Activex Scripting standard can be used in an ASP page.

The scripts are embedded or included into an HTML page. There are 3 methods to do this:

1] Specify a particular scripting language as the default using "Internet Service Manager".
This will be applied to all pages unless explicitely changed in particular page.
2] Specify a scripting language for a single page using ASP directive.
<% @ LANGUAGE="any one scripting language" %>
This should be the first statement in the page.
3] Mix multiple scripting languages in a single ASP page by using the extended <script> tag.
<SCRIPT LANGUAGE="any one scripting language" RUNAT="server>
This is applied to the code with <SCRIPT> tags.


The actual scripts can be embedded in 2 ways:
1] Using script delimeters <% and %>
<% -----
-----
----
------ %>
After you have specified particular scripting language as default language, it can be
used in ASP page, simply by using delimeters <% & %>. The code written within these
delimeters are always processed in-line - relative to their position in the surrounding
HTML.

2] Writing script with <SCRIPT> and </SCRIPT> tags.
<SCRIPT LANGUAGE="any one scripting language" RUNAT="server>
-----
-----
</SCRIPT>
ASP does not guarantee the order of execution of script written in <SCRIPT> block. It gets
processed either at the beginning or at the end - it won't get processed in-line.
Most of the times, and not as a rule, web server first processes the scripts written in
the language other than ASP default language; and processes scripts written in ASP default
language at the end.

This syntax is generally used when:

1] Writing, Procedures or functions: Code written in function and procedure is executed
only when "called" from main code.
2] Use multiple scripting languages: When one scripting language is to be used as the
primary language, but need to call a function from another language. This is
particularly useful when one language has particular functions or methods that
another language lacks.


================================================================

=> Writing on to the page

1] Response.write: Write method of Response object is used.
e.g:
<BODY>
Now the time will be: <%response.write()%>
</BODY>
2] Output directive: Used to display value of expression. The expression might be a simple
variable, a function or procedure or a complex expression. Actually, the server will
internally map this directive to write() method of response object.

Whereas the delimeters <% and %> indicate a script, the delimeters <%= and %> are used
to indicate value of a variable.
e.g:
<BODY>
Now the time will be: <%=TIME%>
</BODY>


Both the methods are interchangeable. But there are some situatins where one method is
better than the other.
->Response.write(), is easier to use when you need to output the value of expression within
script.
->Output directive, is easier when you want to output the value of expression within a
section of HTML code.

================================================================