ASP Web Policies

Page address: http://www.mnsu.edu/its/web/resources/training/aspwebpolicies.html

... > Resources > ASP Web Policies

Coding Guidelines

  • Develop ASP pages separate from HTML pages; i.e. default.asp contains the ASP behind defaultform.asp
  • Use these naming conventions for ASP pages (except name HTML files as ".html" not ".htm")
  • Begin pages with the following:
    <%@ Language=VBScript %>
    <%
    Option Explicit
    ' By declaring 'Option Explicit' all variables
    ' are required to be initialized using the 'Dim' statement
    ' The response buffer caches all response data that will be
    ' sent to the client until the response is finished. Then it
    ' sends all the data at one time.
    Response.Buffer = True ' Enable to improve performance
  • All logout buttons are not to be JavaScript but rather forms that post
  • Always position HTTP header statements below Server.Transfer statements to prevent duplicate header entries
  • If the page should not be cached, include DisableClientCache.inc immediately below the above opening code
  • Free rowset objects when done using them. For example:
    rstCourseList.Close
    Set rstCourseList = Nothing
  • Always free session variables to conserve server memory usage
    'Free the Session("strCourseID") object
    Session.Contents.Remove("strCourseID")
  • Always close the connection to the database at the end of every ASP page
  • Perform validation on the server side at the page level; as the user attempts to move from one page to the next, validation must be enforced before they are allowed to move to the next page.

Code Formatting

Screen space should be conserved as much as possible, while still allowing code formatting to reflect logic structure and nesting. Indent standard nested blocks one tab or four spaces.

  • Indent the overview comments of a procedure one space.
  • Indent the highest level statements that follow the overview comments four spaces, with each nested block indented an additional four spaces.

Begin each page with the following documentation:

'*********************************************************
' Purpose: Locates the first occurrence of a specified user in the UserList array.
' Inputs: strUserList(): the list of users to be searched.
' strTargetUser: the name of the user to search for.
' Returns: The index of the first occurrence of the strTargetUser in the strUserList array.
' If the target user is not found, return -1.
'*********************************************************

Variable Naming Conventions

To enhance readability and consistency, use the following prefixes with descriptive names for variables in your VBScript code.

SubtypePrefixExample
BooleanblnblnFound
BytebytbytRasterData
Date (Time)dtmdtmStart
DoubledbldblTolerance
ErrorerrerrOrderNum
IntegerintintQuantity
LonglnglngDistance
ObjectobjobjCurrent
SinglesngsngAverage
StringstrstrFirstName
ADO Objects
ConnectioncnncnnDevSQL
FieldfldfldName
RecordsetrstrstStudent

Must-read Resources