How I may help
LinkedIn Profile Email me!
Call me using Skype client on your machine


Reload this page Active Server Pages

Here are my notes and resources I have found useful when doing ASP programming. Let me know what you find helpful or missing.

 

Topics this page:

  • History/Versions
  • ASP Coding
  • Data Flow
  • HTML GET vs. PUT
  • Object Model
  • Includes
  • Error Handling
  • Flat File Operations
  • Opening & Closing Databases
  • Doing a Recordset
  • ASP Packages
  • ASP & Front Page
  • Resources
  • Your comments???
  •  

    Site Map List all pages on this site 
    About this site About this site 
    Go to first topic Go to Bottom of this page



    Set screen History of Active Server Pages (ASP's)

      ASP was first announced by Microsoft in November, 1996 (code named "Denali") and introduced March 97 to manage HTTP 1.0 as a part of Microsoft's Internet Information Server version 3 (code name “Gibraltar”).

      ASP 2.0 came with IIS 4.0 installed from the NT4 Option Pack as Personal Web Server (PWS) and also on CD 2 of Visual Studio 6. PWS can also be installed on Windows 95 from the setup.exe in Add-ons\pws folder from the Win 98 CD after the 986KB Feb 98 WinSock2 Upgrade for Windows 95.

      ASP 3.0 comes with IIS 5.0 shipped with Windows 2000. It introduces the Server.Transfer method (which redirects without a trip back to the client) and the Server.Execute method (which, unlike includeson this page, parses code conditionally).

      IIS 5.1 is installed with Windows XP Professional (not the XP Home version).

      ASP.NET (pronounced "dot net") has a whole new architecture — the .NET Frameworkanother page on this site which references "code behind" program logic written in C Sharp or other language that compiles into MSIL. Because each file of a particular language is handled by that language's compiler, unlike ASP, languages cannot intermix in a single program file. This also requires ASP.NET to run on IIS server, and not under PWS.

      ASP.NET 2.0, released with Visual Studion 2005, introduces controls such as <asp:Login

      ASP.NET 3.5 was released with Visual Studio 2008.

      Microsoft's ASP.NET 4.0 preview contains the AJAX Template Library and the AJAX Client Library for ADO.NET Data Services.

     

     
    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen ASP Coding

      When a client's Web/Internet browser clients requests a URL with an .asp file instead of an .htm, the ASP Interpreter (ASP.DLL) is invoked. MS .NET services also recognize .aspx files for processing only by ASP.NET servers. Caution! Unlike .htm files, the full http:// reference must be used to invoke ASP files through a web application server because the whole point of using ASP files is to dynamically generate Javascript and HTML code rather than serving up static .htm files.

      The ASP interpreter acts on blocks of code between delimiter tags <% and %>

      The first line of an ASP file specifies the syntax to be expected by the interpreter:

      <%@Language=VBScript%>
      This is the default. Specify Language=JScript to use Javascript syntax between delimiter tags <% and %>
      <%@Language=Javascript runat="server"%>

      Caution! Non-default code scripts (such as JScript within VBScript file) run on the server are (on IIS 4.0) executed before default script code.

      An example of how an ASP.NET page begins:

      <%@ Page Language="vb" AutoEventWireup="false" Codebehind="Webform1.aspx.vb" Inherits="MyApp.WebForm1" %>

      The Page Language must be "vb" because to create this, in Microsoft Visual Studio 2004, open a new Visual Basic Project and select template ASP.NET Web Application. Resources for several projects are grouped into a Visual Studio Solution.

      ASP.NET header <% Explicit="true" takes the place of <% Option Explicit %>

      My sample "MySolution" has these resources:

      • References
      • AssemblyInfo.vb
      • Global.asax
      • Styles.css
      • Web.config

      • MyProj.vsdisco
      • WebForm1.aspx


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Data Flow

      IIS returns to the calling client browser variables from Intrinsic Objects such as the user's browser type, URL, screen resolution, etc. tool ASP Server Variables for this machine/session

      Instead of Response.Write use this shortcut with the equal sign:

        <%=oRS("PeopleNameLast") %>

      Instead of specifying just the variable name, professional ASP programmers usually encase the field in a function to format the field's values, such as using the oRS() function to retrieve the value of a database field or the ToCurrency() function to format numbers using the client's local currency symbols and separators.

      In contrast, JSP pages

        <% if( request.getMethod().equalsIgnoreCase("POST"))
        {%>
          User id:<%=request.getParameter("frmField1")%>
        <%}%>

    Set screen String Handling

      James Musson's webpage article MSDN article notes that with ASP, the performance of issuing several Response.Writes (the quickest) is slower than string concantenation (the slowest). He also proposes an efficient StringBuilder method.


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen HTML FORM ACTION GET vs. PUT

      To retrieve a variable named "X" in a form sent with METHOD="GET", use QueryString("X"). This variable name appears after the http: URL after ?. Each variable is separated by an ampersand (&).

      To retrieve a variable named "X" in a form sent with METHOD="PUT", use Request.Form("X"). For example, the code to redisplay a radio button variable by an ASP program that sends to itself:

      <% if Request.Form("X") = "on" then "selected" %>

      Instead of these native commands, professional ASP programmers use a custom function (typically from a common library) to consistently process values. For example, I run data to be stored in SQL databases through the ToSQL() function, which converts single quotes into double quotes. I use the ToHTML() function to format special characters to HTML encoding.

      NOTE: In the Ruby language, this information is obtained by coding params[:id].


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen ASP Document Object Model

    • The Request object supplies information from a client visitor (Form, QueryString, ServerVariables, Cookies, ClientCertificate). Its TotalBytes property provides how much data is transferred each time.
    • The Response object contains methods for building a response to the client (End, Redirect, AddHeader, Write, BinaryWrite, Clear, Flush) and the Cookies collection. Its properties are Buffer, Charset, Expires, ExpiresAbsolute, CacheControl, ContentType, Pics rating, Status line text. IIS5 added AppendToLog.
    • ObjectContext method SetAbort triggers the OnTransactionAbort event. SetComplete transactions triggers the OnTransactionCommit event.
    • The ASPError object (new since IIS5) exposes properties of the last error when Server.GetLastError is called, such as the Category and shorter Description or longer ASPDescription of the error Source and which Line and Column in the File causing the error.
    • The Server object also has methods to do HTMLEncode, URLEncode, and MapPath. Its ScriptTimeout property manages its lifetime.
    • Application methods Lock and UnLock control availability of objects in its Contents and StaticObjects collections. Variables available to all users are defined with Application_OnStart and _OnEnd events.
    • The Session object holds the CodePage, LCID, SessionId, and Timeout properties pertaining to a particular visitor. Like the Application object, Contents and StaticObjects collections for each user session are managed with Abandon and Contents.Remove methods.


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set this at top of window. Web Environment Variables

      Variables available to each session object is defined with Session_OnStart and _OnEnd events.

      objRecordset.Fields("DATE") = Now()
      objRecordset.Fields("HTTP_USER_AGENT") = Request.ServerVariables("HTTP_USER_AGENT")
      objRecordset.Fields("HTTP_REFERER") = Request.ServerVariables("HTTP_REFERER")
      objRecordset.Fields("QUERY_STRING") = Request.ServerVariables("QUERY_STRING")
      objRecordset.Fields("REMOTE_ADDR") = Request.ServerVariables("REMOTE_ADDR")
      objRecordset.Fields("REMOTE_HOST") = Request.ServerVariables("REMOTE_HOST")
      objRecordset.Fields("SERVER_PORT") = Request.ServerVariables("SERVER_PORT")
      objRecordset.Fields("URL") = Request.ServerVariables("URL")
      

      CGI coding

      print "QUERY_STRING ", $ENV{'REMOTE_ADDR'}, "\n";
      

      These variables maintained internally by web application programs such as CGI, ASP, and JSP.

      Environment VariableDescription
      AUTH_TYPE The authentication method used to validate a user.
      DOCUMENT_ROOT The directory from which Web documents are served.
      CONTENT_TYPE The MIME type of the query data, such as "text/html".
      CONTENT_LENGTH The length of the data in bytes passed to the CGI program through standard input
      GATEWAY_INTERFACE The revision of the Common Gateway Interface that the server uses
      HTTP_ACCEPT A list of the MIME types that the client can accept.
      HTTP_FROM The email address of the user making the request. Most browsers do not support this variable.
      HTTP_USER_AGENT The browser the client is using to issue the request.
      HTTP_REFERER The URL of the document that the client points to before accessing the CGI program.
      PATH_INFO Extra path information passed to a CGI program.
      PATH_INTERFACE The translated version of the path given by the variable PATH_INFO.
      QUERY_STRING The query information passed to the program. It is appended to the URL with a "?".
      REQUEST_METHOD The method with which the information request was issued.
      REMOTE_HOST The remote hostname of the user making the request.
      REMOTE_ADDR The remote IP address of the user making the request
      REMOTE_USER The authenticated name of the user.
      REMOTE_IDENT The user making the request. This variable will only be set if the NCSA IdentityCheck flag is enabled, and the client machine supports the RFC 931 identification scheme (ident daemon).
      SCRIPT_NAME The virtual path (e.g. /cgi-bin/program.pl) of the script being executed.
      SERVER_NAME The serevr's hostname or IP address.
      SERVER_SOFTWARE The name and version of the server software that is answering the client request.
      SERVER_PROTOCOL The name and revision of the information protocol the request came in with.
      SERVER_PORT The port number of the host on which the server is running.

    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen ASP Object Model

     

      The global.asa file contains initialization code for the user's session and the application.

     
    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Includes

      Use "include" preprocessor directives to dynamically add code from another file whenever it's invoked. The adovbs.inc is in most ASP pages to define common literals.

      Including other files makes it easier to keep common elements such as menu bars, copyright statements, etc. consistent across in all pages of a website by using a single source file for the contents. This is typically used to enforce login before users can access a page:

      <!--#includesecuritylevel1required.asp"-->
      ' Define VBScript Constants:
      <!-- #include file="common.asp" -->

      If the file is not in the folder, specify instead

      <!-- #include virtual="../lib/edits.asp" -->

    • server.execute conditionally executes a dynamically generated string naming an asp script to be executed. Control is returned after that is executed.

      Server.Execute("Lookup.asp")

    • To abort ASP processing and send the page to the client:

      Response.End

    • To ...

      Response.Flush

    • To forward user to another URL:

      Response.Redirect "http://www.dilbert.com"

      Caution! A common mistake is to leave out "http://".

      server.transfer new to Windows 2000 unlike redirect, does not return to the browser but switches to a different page/site.

      For ASP Developers:  
    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Error Handling

      webpage article Click to create ASP error

      Click "Submit" without entering any data on and see a sample error page:

        Microsoft OLE DB Provider for ODBC Drivers error '80004005'

        [Microsoft][ODBC Microsoft Access Driver] Field 'tblAdoAdd.FirstName' cannot be a zero-length string.

      Add this under the </HTML> in ASP pages to trap time-outs:

      <%
      Sub OnTranactionAbort()
          response.clear
          Response.Write "Script timed out."
      end sub
      %>

     

     
    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Flow Control

       
    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Flat File Operations

      To operate on individual files (such as .mdb), ADO uses built-in methods of the File System Object of the ADO (Active Database Objects) interface.

      To create (instantiate) a object called objFSO

      Dim objFSO
      set objFSO=Server.CreateObject("Scripting.FileSystemObject")
      	
      To delete prior output file (if one exists):

      If objFSO.FileExists(Server.MapPath("myfile")) Then
         objFSO.DeleteFile Server.MapPath("myfile")
      End IF
      Set objFSO = Nothing
      	

     

     
    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Opening and Closing Databases

      1. Create (instantiate) an ADO Connection (cnn) object:

      Dim cnnXXX
      set cnnXXX=Server.CreateObject("ADODB.Connection")
      2. Open a database using a Connection Stringanother page on this site

      cnnXXX.ConnectionString = strConn
      cnnXXX.Open

      3. Create (instantiate) a Recordset (rst) to hold the output:

      Dim rstXXX
      Set rstXXX = Server.CreateObject("ADODB.Recordset")
      rstXXX.CursorLocation=3
      rstXXX.CacheSize=10

      4. Define a SQL dynamic queryanother page on this site string, (which ends with a semicolon):

      Dim strSQL
      strSQL = "SELECT * FROM People;"

      5. Execute the SQL query through the connection and into the recordset:

      Set rstXXX = cnnXXX.Execute( strSQL )

      6. Do stuff with the data

      7. Finally, close the object and set it to nothing:

      cmmXXX.Close
      set cnnXXX=Nothing

     

      The ConnectionString property identifies the data source to be used for retrieving and storing the information manipulated by the data control. It includes information OLE DB provider used to communicate with the data source.

      The RecordSource property identifies the information managed by the data control. This could relate to all of the information in a single table, some of the information from a single table, or information stored in multiple tables in the data source.

      webpage article Young Alex Haneng offers clear explanations

     
    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Doing Stuff With a Recordset

      You can perform insert, update, delete, or selection of data on a database.

      To save the file to XML format:

      rstXML.Save Server.MapPath("db_xml.xml"), adPersistXML

      Using a Forward-Only Cursor on an ADO Database To use the oRS object's default method to return the value of a column named PeopleNameLast from the first row:

      oRS.MoveFirst
      Response.Write oRS("PeopleNameLast")

      You can also use method MoveLast for the last row or MoveNext. Note that cursors to simple recordsets cannot move backward (using MovePrevious) through the database.

     

     
    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen ASP Packages



      dotnetnuke (DNN) is a one-stop shop for hosting of open-source collaboration suites. Some prefer the XMod module (particularly the Calendar widget). Add-on controls for it are from Infragistics.

      Michael Washington's tutorials.

      Beginning DotNetNuke 4.0 Website Creation in C# 2005 with Visual Web Developer 2005 Express: From Novice to Professionalby Nick Symmonds

      Professional DotNetNuke 4: Open Source Web Application Framework for ASP.NET 2.0 (Programmer to Programmer) By the architects: Shaun Walker, Joe Brinkman, Bruce Hopkins, Scott McCulloch, Chris Paterra, Patrick J. Santry, Scott Willhite, Dan Caron

      Professional DotNetNuke ASP.NET Portals by Shaun Walker

      Beginning DotNetNuke Skinning and Design by Andrew Hay and Shaun Walker

     
    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen ASP and Front Page Together

      ASP takes Microsoft Front Page controls to another level of functionality.

    • Each IS/IPA must install on their servers software to support Microsoft Front Page Extensions and Active Server Pages.

    • Avoid using FrontPage 97 or FrontPage 98 when working with ASP files. The Personal Web Server which comes with FP does not run Active Server Pages. If you try to execute an ASP file with it installed, you will see your ASP code printed on the screen exactly as you typed it.

      During installation, FP muscles itself in as the default application to be invoked when you double-click on file names ending with ".asp". To change this in Windows Explorer, hold the shift key down while right clicking on an .asp file, then select Open With... and choose a new application, such as Wordpad, Notepad, or an HTML editor like Allaire's HomeSite that doesn't change coding.

    • On a stand-alone PC, before installing FP, dial up your ISP to get TCP/IP in memory. FrontPage 98 and PWS98 (PWS4), need 32bit TCP/IP to be "running". To avoid a common annoyance of the computer dialing automatically whenever it starts, reconfigure Internet Explorer and go to View, Connect and choose "I connect to the Internet via the LAN" rather than "through a Modem". This satisfies PWS and you just have to make sure you actually DO connect to your ISP if you want to surf the web or check your email.

    • When installing NTOP, if you choose to install the HTML Internet Manager, you will be able to create and manage virtual directories from a browser on another machine.

     

      gotdotnet Workspaces is an online collaborative development environment where .NET developers can create, host and manage projects throughout the project lifecycle.

     
    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Resources

     

     
    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Portions ©Copyright 1996-2014 Wilson Mar. All rights reserved. | Privacy Policy |

    Related:

  • IIS Configuration
  • Web Development Tools
  • Perl
  • Application Development
  • Web Projects
  • Javascript Coding

  • How I may help

    Send a message with your email client program


    Your rating of this page:
    Low High




    Your first name:

    Your family name:

    Your location (city, country):

    Your Email address: 



      Top of Page Go to top of page

    Thank you!