ASPLecture Handouts

Document Sample
ASPLecture Handouts Powered By Docstoc
					                    Setting Up ASP on Your System
Installing under Windows 2000 (IIS 5.0) and Windows XP (IIS 5.1)

   1) Start è Settings è Control Panel è Add/Remove Programs
   2) Click Add/Remove Windows Components
   3) Select Internet Information Services (IIS) (don’t check or uncheck this option)
   4) Click Details
   5) Check Common Files, Internet Information Services Snap-In, and World
      Wide Web Server. Optionally, check Documentation
   6) Click OK
   7) Click Next

Setting Up ASP on Your Site

   1) Start è Settings è Control Panel è Administrative Tools è Internet Services
       Manager
   2) Expand the tree until Default Web Site is visible
   3) Right-click Default Web Site and choose Properties
   4) Click the Home Directory tab
   5) Optionally, enter your ASP application’s name in the Application name field and
       select the desired Execute Permissions and Application Protection. The default
       values for these fields are fine.
   6) Click Configuration
   7) Click the App Options tab
   8) Here you can change session lifetimes, ASP buffering, the default ASP language,
       and the timeout for stalled scripts. Again, the default values are fine.
   9) Click the App Debugging tab
   10) If you have installed the Script Debugger (see attached sheet for how-to) be sure
       to check Enable ASP server-side script debugging. For security reasons it is
       generally not a good idea to have Enable ASP client-side script debugging
       checked.
   11) Click OK
   12) Click OK
   13) Click the Directory Security tab
   14) Click the Edit button under Anonymous access and authentication control
   15) Here you can control whether your site is accessed with or without a password.
       To restrict access with a password, uncheck Anonymous access and check either
       Basic authentication or Integrated Windows authentication. Note that the
       integrated authentication requires you to designate (or create) a Windows NT
       account for access to the site.
   16) Click OK
   17) Click OK
                Setting Up A DSN On Your System

For an MS Access Database (Windows 2000/XP)

   1) Create your database in Microsoft Access first
   2) Start è Settings è Control Panel è Administrative Tools è Data Sources
       (ODBC)
   3) Click the System DSN tab
   4) Click Add
   5) Select Microsoft Access Driver (*.mdb)
   6) Click Finish
   7) Type the desired name of your DSN in the Data Source Name edit box and a
       description in the Description box
   8) Click Select
   9) Select the desired Access .mdb file
   10) Click OK
   11) Click OK

For a SQL Server 7 Database (Wi ndows 2000/XP)

   1) Create your database in SQL Server first
   2) Start è Settings è Control Panel è Administrative Tools è Data Sources
       (ODBC)
   3) Click the System DSN tab
   4) Click Add
   5) Select SQL Server
   6) Click Finish
   7) Type the desired name of your DSN in the Name edit box and a description in the
       Description box
   8) Select the name of the SQL server where the database resides from the Server
       dropdown box
   9) Click Next
   10) Depending on how you set up MS SQL Server choose the appropriate login
       method. Usually, SQL Server authentication is easier to configure properly. Refer
       to the MS SQL Server Books Online for information on configuring SQL Server
   11) Click Next
   12) If an error occurs correct the information and try again
   13) Select the desired default database from the Default dropdown
   14) Click Finish
   15) Click Test Data Source to test your DSN connection
   16) If there are no errors, click OK
VBScript
Basic Syntax (no pun intended)

   •   Simple syntax (no semicolons, statements restricted to one line)
   •   Apostrophy ' used for comments
   •   Variables do not have to be declared before using them
   •   Subroutines and functions: subroutines are equivalent to functions that return void
       in C/C++
   •   Private, Public allow you to give variables, subroutines, and functions
       application- or page-scope.
   •   Case-insensitive

Language Features:

   •   Only one variable data type: the Variant
   •   Variants can be null or store any of the following types of data: integer, single
       (float), double, byte, Boolean, currency, date/time, or string
   •   Additionally, variants can store references to objects
           o When used as a reference to an object, you must assign using the Set
                keyword.
           o You can “disconnect” a reference from an object by assigning the variable
                to Nothing (using the Set keyword, of course!)
   •   Arrays can be resized using the ReDim statement

Things to Watch Out For

   •   Be sure you know what type of data you are working with
           o Helpful to use data-conversion functions such as CBool, CSng, CStr, CInt,
               etc. to explicitly force variants to the desired data type.
           o Use the & operator and not the + operator to concatenate strings.
   •   Parameters passed to a subroutine are not enclosed in parentheses
   •   Parameters passed to a function are required to be enclosed in parentheses
   •   Two kinds of division
           o Integer division operator \                5\2=2
           o Floating point division operator /         5 / 2 = 2.5
   •   Some subroutines and functions have default values for certain parameters. To use
       the default simply omit the corresponding argument. If the default is at the
       beginning or the middle of the parameter list just use commas without anything in
       between: rs.Open "Students", conn, , , adCmdTable
Helpful Hints

   •   Type Option Explicit on one line near the start of your scripts to force variable
       declarations. This helps you prevent bugs caused by mistyping variable names.
   •   IsNumeric function returns True if a string represents a valid number
   •   IsDate function returns True if a string represents a valid date
   •   Dictionary object allows you to create a hash table
          o Accessing the values is as easy as using an array (same notation)
          o http://msdn.microsoft.com/library/default.asp?url=/library/en-
               us/script56/html/jsobjDictionary.asp?frame=true for more info

Debugging

   •   Set up IIS to allow ASP sever-side debugging
   •   Download the Windows Script Debugger
           o Allows you to set breakpoints, step through code, and examine variables
           o Also allows you to debug client-side scripts from Internet Explorer
ASP Examples:

Source Code

    <% @Language = VBScript %>
    <% Option Explicit %>
    <html>
    <head>
      <title>Simple ASP Example</title>
    </head>

    <body bgcolor="#FFFFFF">

    <p>Let's count to 10 in ASP!</p>

    <p>
    <%
          Dim i
          For i = 1 To 10
             Response.Write "<b>" & i & "</b> " & vbNewLine
          Next
    %>
    </p>

    <p>Now let's count to 5!</p>
    <% For i = 1 To 5 %>

    <p><b><%=i%></b></p>

    <% Next %>
    </body>
    </html>

Page

Let's count to 10 in ASP!
1 2 3 4 5 6 7 8 9 10
Now let's count to 5!
1
2
3
4
5
More ASP Examples

Forms

(form.htm)

   <html>
   <head>
     <title>Please say Hello</title>
   </head>
   <body bgcolor="#FFFFFF">

   <form action="sayhello.asp" method="POST">
   <p><b>Please enter your name:</b>
   <input type="text" name="YourName" id="YourName"></p>
   <p><input type="submit" value="Say Hello!"></p>
   </form>

   </body>
   </html>

(sayhello.asp)

   <% @Language = VBScript %>
   <% Option Explicit %>
   <%
       Dim YourName
       YourName = Request.Form("YourName")
   %>
   <html>
   <head>
      <title>Hello <%=YourName%>!</title>
   </head>
   <body bgcolor="FFFFFF">

   <h2>Hello <%=YourName%>!</h2>

   <p>Nice to meet you!</p>

   </body>
   </html>
Sample Database




  •   This database keeps track of students, professors and their classes.
  •   It has 4 tables: Students, Professors, Courses, and Rosters
  •   Students stores information about students and uses a StudentID field as a unique
      id for each record in the table.
  •   Professors stores information about professors and uses a ProfessorID field as its
      unique id.
  •   Courses stores the name of the class and the id of the professor teaching it. This is
      a relationship between the Professors table and the Courses table.
  •   Rosters defines the relationship between the Students table and the Courses table.
      It stores both the id of the class and the id of the student taking the class.
List All Students In A Course

(list_roster.asp)
    <% @Language = VBScript %>
    <% Option Explicit %>
    <%
       Response.Buffer = True

         ' Read the course name from the database
         Dim conn, query, rs, CourseName

         Set conn = Server.CreateObject("ADODB.Connection")
         conn.Open "DSN=MyDSN;Database=MyData;UID=sa;PWD=l33t"

         query = "SELECT Course FROM Courses WHERE CourseID = "
         query = query & Request.Form("CourseID")

         Set rs = conn.Execute(query)

         If rs.EOF Then
            Response.Redirect "roster_error.htm"
         End If

         CourseName = rs("Course")
         rs.Close
    %>

    <html>
    <head>
      <title>Roster For Course <%=CourseName%></title>
    </head>

    <body bgcolor="#FFFFFF">

    <h2>Roster For Course <%=CourseName%></h2>

    <%
         ' Read the roster
         query = "SELECT FirstName, LastName, StudentID FROM "
         query = query & "Students S, Rosters R WHERE "
         query = query & "S.StudentID = R.StudentID AND R.CourseID = "
         query = query & Request.Form("CourseID") & " ORDER BY LastName"

         Set rs = conn.Execute(query)
    %>

Continued on next page…
Continued from last page…

   <table border=0 cellspacing=5>
   <tr>
      <td><b>Student</b></td>
      <td><b>ID Number</b></td>
   </tr>
   <%
       While Not rs.EOF
   %>
   <tr>
      <td><%=rs("LastName")%>, <%=rs("FirstName")%></td>
      <td><%=rs("StudentID")%></td>
   </tr>
   <%
          rs.MoveNext    ' VERY IMPORTANT! DON'T FORGET THIS!
       Wend

      rs.Close
      conn.Close
   %>
   </table>

   </body>
   </html>
Resources

Scripting Downloads

 Windows Scripting Documentation

      Go to http://msdn.microsoft.com/scripting
      Click “Downloads” in the tree view
      Click “Windows Script 5.6 Documentation” in the tree view
      Click “Download”

 Windows Script Debugger

      Go to http://msdn.microsoft.com/scripting
      Click “Downloads” in the tree view
      Click “Windows Script Debugger”
      Click the appropriate download link

ASP Resources

      Microsoft Developer Network ASP Guide
      http://msdn.microsoft.com/library/default.asp?url=/library/en-
      us/iisref/html/psdk/asp/aspguide.asp?frame=true

      LearnASP
      http://www.learnasp.com/learn/newbie.asp

ADO (ActiveX Data Objects) Resources

      Microsoft Developer Network
      http://msdn.microsoft.com/library/default.asp?url=/library/en-
      us/ado270/htm/mdmscadoapireference.asp?frame=true

Books

      SAMS Teach Yourself Active Server Pages in 24 Hours
      Christoph Wille and Christian Koller

      Great examples of ASP, SQL, and ADO. Amazon: new $13.99, used $6.00!!

      SAMS Teach Yourself Transact-SQL in 21 Days
      Bennett Wm. McEwan and David Solomon

  If you want to really learn SQL this is a good book to have.
 nd
2 Edition now available on Amazon: new $24.49, used $15.00

				
DOCUMENT INFO
Shared By:
Tags:
Stats:
views:18
posted:5/24/2011
language:English
pages:10
About if any file u wil find copyright contact me it will be remove in 3 to 4 buisnees days. add me on sanjaydudeja007@gmail.com or visit http://www.ohotech.com/