1 / 22

CIS 451: ASP.NET Debugging and Server-Side Includes

CIS 451: ASP.NET Debugging and Server-Side Includes. Dr. Ralph D. Westfall February, 2009. Error Handling/Debugging. client side vs. server scripts syntax errors logical errors good coding practices to minimize errors testing your code debugging statements.

reid
Télécharger la présentation

CIS 451: ASP.NET Debugging and Server-Side Includes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CIS 451: ASP.NET Debugging and Server-Side Includes Dr. Ralph D. Westfall February, 2009

  2. Error Handling/Debugging • client side vs. server scripts • syntax errors • logical errors • good coding practices to minimize errors • testing your code • debugging statements

  3. Need to Identify as Server Script • code will run on client if doesn't have: • <% • [code] • %> • or • <script language="VB" runat="server"> • [code] • </script> • filetype needs to be .aspx, not .htm(l)

  4. Syntax Errors • spelling • Reesponse.Write("something") • EndIf '2 words: needs a space • missing parts of control structures • For but no Next • If but no End If • extra parts for control structures • extra Next or extra End If at end

  5. Syntax Errors - 2 • using a method as a property • Response.Write = "Welcome" • don't use = with methods • using a property as a method • buffer("true") • properties are values, so need to use =

  6. Syntax Errors - 3 • writing to a "read only" property Dim prices() As Double = {3.00, 2.00} prices.Length = 5 'read only property • using Set to create an object • Set objMail = _ Server.CreateObject("CDO.Message") • 'remove Set (ASP 3.0 still needs Set)

  7. Logical Errors • division by a variable that has value of zero if Option Explicit or Strict is not On • a = 2 • c = a / b 'no value given for b • type mismatch • e.g. can't do arithmetic with text • 5 / "hello" • missing period can cause a type mismatch • a=CInt(RequestQueryString("card")) • 5 / a

  8. Good Coding Practices • indent code inside loops and conditionals • "pretty listing" (automatic in VS.NET) • For intI = 0 to 2 • intJ = intI • Next I • use comments where appropriate • 'single quote creates a comment

  9. Good Coding Practices - 2 • use Option Strict at start of file <%@ Page Language="vb" Strict="true"%> • forces you to use Dim for all variables • helps spot spelling mistakes • forces you to handle all type conversions explicitly txtCount.Text=CStr(intCount)

  10. Good Coding Practices - 3 • use consistent object naming prefixes • btnSubmit 'a button • txtLastName 'a textbox for data • capitalize function names e.g. conversions • CInt(7.3) 'Convert to Integer • CCur(9.9) 'Convert to Currency

  11. Good Coding Practices - 4 • type checking: is data what you expect? • If IsNumeric(Request.Form("num")) Then • intTot = intTot + intNum • End If • type conversion: change data so it is usable • intValue = CInt(dblItem1 + dblItem2)

  12. Good Coding Practices - 5 • use subprocedures and/or functions • for anything substantial (5 or more lines?) that gets done in more than 1 place • advantages: • shorter program • easier to debug and maintain • may be able to reuse them in other programs

  13. Good Coding Practices - 6 • use "server-side includes" in .aspx files • <% 'prices.aspx file • Dim dblProdPrice(11) • dblProdPrice(0)=29.99 'etc. • %> • <html> <!-- shopping cart file --> • <!-- #include file="prices.aspx"--> • advantages similar to subprocedures, etc. See Notes Page

  14. Testing Your Code • test the different ways a user could go through the application • example: shopping cart with 2 catalog pages • entry page to catalog page 1 to checkout • entry page to catalog page 2 to checkout • entry, catalog 1, catalog 2, checkout • entry, catalog 2, catalog 1, checkout • using browser Back button instead of form button? • using link instead of button?

  15. Testing Your Code - 2 • test possible data values • example: zip codes • boundary values (included, or not?) • 00000 and 99999 • values in between boundaries • 00001 to 99998 • out-of-bounds values • negative #s? 6 digit #s? • text #s? (ninety thousand and one)

  16. VS Debugging Capabilities • break points and icons for stepping through code • Step Into, Step Over, Step Out • special windows • Locals, Output, Watch, View Stack, etc.

  17. Debugging Statements • insert "trace" statements to determine values before code where problem is • Response.Write([variable name]) • use <form method="get" > so you can see form input values in query string • MsgBox to show specific values

  18. Debugging with "Include" Files • some programmers put tracing procedures in separate file • add #include file=[trace file name] at top of file being debugged • need to then insert calls to trace file procedures in code • NET tracing capabilities

  19. More on Server Side Includes • special features for HTML files only? • extension is .shtml or .shtm so server knows that special processing required • #fsize - gives file size • #flastmod - gives file last modified date • include works in both ASP and HTML • # include - includes text (code) from another file so it is processed as if it is in the current file

  20. Server Side Include Issues • data is text, so could use .txt as extension • can hide file by using .aspx extension • Microsoft recommends .inc extension • to conveniently identify include files • convenient way to keep data in programs up-to-date • e.g., put shopping cart product prices data in an include, then update just that file

  21. Using Server Side Includes in ASP.NET • need to put "directive" in HTML comments <!--#include file="file1.aspx"-> 'path not needed if in current directory • can use physical path (address on drive) <!--#include file="[C:\path\]file.aspx"-> • can also use virtual path (server address) <!--#include virtual="[path]/file.aspx"->

  22. SSI Exercise • view Using Server Side Includes • click "basic page," View>Source, edit URLs and Save As basic.shtml • note: save it as .shtml, not .html • also save code for the other linked pages (includes) in same directory • modify include files • view effects on basic.shtml in browser

More Related