SlideShare une entreprise Scribd logo
1  sur  34
Télécharger pour lire hors ligne
Introduction to ASP.NET




                          1
ASP.NET

•   ASP.NET is a managed framework that facilitates building server-side
    applications based on HTTP, HTML, XML and SOAP. To .NET
    developers, ASP.NET is a platform that provides one-stop shopping for
    all application development that requires the processing of HTTP
    requests.




                                                                            2
A platform on a platform

•   ASP.NET is a managed framework that facilitates building server-side
    applications based on HTTP, HTML, XML and SOAP
     – ASP.NET supports building HTML-based applications with Web forms,
       server-side controls and data binding
     – ASP.NET supports building non-visual request handlers and Web services


                          W eb B row ser


                               HTM L




                                                     HTTP Runtime (IIS/ISAPI)
                      W e b S e r v ic e C lie n t
                                                                                S ys te m .W e b
                                                                                 (A S P .N E T )
                                XM L




                       M u ltim e d ia C lie n t


                        M P 3 /P N G /W M V

                                                                                                   3
A new and better version of ASP

•   ASP.NET is a much improved replacement for original ASP framework
     – All ASP.NET code is fully compiled prior to execution
     – ASP.NET doesn't require the use of scripting languages
     – ASP.NET allows for total separation of code from HTML
     – ASP.NET state management works in a Web farm environment




                                                                        4
ASP.NET Internals

•   ASP.NET uses a new CLR-based framework to replace ISAPI/ASP architecture
     – ASP.NET requests are initially handled by the HTTP runtime of IIS
     – ASP.NET ISAPI extension DLL redirects requests to ASP.NET worker process




     HTTP request
        *.ashx            ISAPI               ASPNET_ISAPI.DLL                          ASP.NET
        *.aspx
                        Extension                 ISAPI extension
        *.asmx
                                                    for ASP.NET
                                                                    Named Pipes         pipeline
        *.disco         Manager
        *.soap


                                    INETINFO.EXE                                   ASPNET_WP.EXE
                              HTTP runtime provided by IIS                        ASP.NET Worker Process




                                                                                                           5
ASP.NET Internals

•   Requests are process in the quot;HTTP pipelinequot; inside ASP.NET worker process
     – Pipeline always contains HttpRuntime class
     – Pipeline always contains exactly one HTTP handler object
     – Modules are interceptors that can (optionally) be placed in pipeline
     – HttpContext is a valuable class accessible from anywhere in pipeline


                                   ASP.NET worker thread 1

                     HttpRuntime                                        HTTP Handler
                                   Module 1                  Module 2
                        Class                                                MyPage.aspx




                                   ASP.NET worker thread 2

                     HttpRuntime                                        HTTP Handler
                                   Module 1                  Module 2
                        Class                                               MyHandler.ashx




                                   ASP.NET worker thread 3

                     HttpRuntime                                        HTTP Handler
                                   Module 1                  Module 2
                        Class                                           Class1 from MyLibrary.dll




                                   ASP.NET Worker Process
                                         ASPNET_WP.EXE                                              6
HttpContext Properties

         Type                   Name                         Description

     HttpContext          Current (Shared)     Context for request currently in progress

 HttpApplicationState       Application             Appliction-wide property-bag

   HttpApplication       ApplicationInstance        Application context (modules)

   HttpSessionState           Session                  Per-client session state

     HttpRequest              Request                    The HTTP request

    HttpResponse              Response                   The HTTP response

     IPrincipal                 User                 The security ID of the caller

    IHttpHandler              Handler             The handler dispatched to the call

     IDictionary               Items                  Per-request property-bag

  HttpServerUtility            Server                URL Cracking/Sub-handlers

      Exception                Error           The 1st error to occur during processing




                                                                                           7
Programming against the HttpContext object




   Imports System.Web

   Public Module PipelineUtilities
     Sub SayHello()
       Dim ctx As HttpContext = HttpContext.Current
       If ctx Is Nothing
         '*** executing outside the scope of HTTP pipeline
       Else
         ctx.Response.Write(quot;Hello, quot;)
         Dim name As String = ctx.Request.QueryString(quot;namequot;)
         ctx.Response.Output.WriteLine(name)
       End If
     End Sub
   End Module




                                                                8
Integrated compilation support

•   ASP.NET provides integrated compilation support to build source files into
    DLLs in just-in-time fashion
     – Auto-compilation supported for .aspx, .ascx, .asmx and .ashx files
     – The generated assembly is stored in subdirectory off of CodeGen
       directory
     – ASP.NET automatically references all assemblies in bin directory
     – ASP.NET automatically references several commonly-used .NET
       assemblies
     – Other assemblies can be referenced through custom configuration
     – Shadow-copying allows DLLs to be overwritten while application is
       running




                                                                                 9
Hello, World using VB.NET in an ASP.NET page




<%-- MyPage1.aspx --%>
<%@ page language=quot;VBquot; %>
<html><body>
  <h3>My Page</h3>
  This page contains boring static content and
  <%
    Dim s As String = quot;<i>exciting dynamic content</i>quot;
    Response.Write(s)
  %>
</body></html>




                                                          10
System.Web.UI.Page

•   An .aspx file is transformed into a class that inherits from Page class
     – Page class provides HTTP handler support
     – Page class members are accessible from anywhere inside .aspx file
     – Much of Page class dedicated to generation of HTML
     – Static HTML in .aspx file becomes part of page's Render method
     – Code render blocks in .aspx file become part of page's Render method
     – Members defined in code declaration blocks become members of page
       class
     – WebForms and server-side controls build on top of Page class
       architecture




                                                                              11
Using reflection from an ASP.NET page




<%@ page language=quot;VBquot; %>
<html><body>
  <%
     '*** note that this variable refers to subtype of Page
     Dim MyType As String = Me.GetType().ToString()
     Dim MyDadsType As String = Me.GetType().BaseType.ToString()

    '*** note that Response is a property of Page
    Me.Response.Write(quot;page type: quot; & MyType & quot;<br>quot;)
    Me.Response.Write(quot;page's base type: quot; & MyDadsType & quot;<br>quot;)
  %>
</body></html>




                                                                    12
System.Web.UI.Page


     Imports System.Web.UI

     Class System.Web.UI.Page

         '*** functionality similar to what's in ASP
         ReadOnly Property Application As HttpApplicationState
         ReadOnly Property Session As HttpSessionState
         ReadOnly Property Request As HttpRequest
         ReadOnly Property Response As HttpResponse
         ReadOnly Property Server As HttpServerUtility
         Property Buffer As Boolean
         Function MapPath(virtualPath As String) As String
         Sub Navigate(url As String)

         '*** functionality new to ASP.NET
         Property ClientTarget As ClientTarget
         ReadOnly User As IPrincipal
         ReadOnly Property IsPostBack As Boolean
         Protected Overridable Sub Render(writer As HtmlTextWriter)
         Event Load As EventHandler


     End Class
                                                                      13
Sample aspx file customizing Page

        <!-- MyPage2.aspx -->
        <%@ Page Language=quot;VBquot; %>

        <html><body>
        <h2>Customer list</h2>
        <ul>
        <%
          '*** code render block becomes part of Render method
          Dim i As Integer
          For i = 0 to (m_values.Count - 1)
               Response.Write(quot;<li>quot; & m_values(i).ToString & quot;</li>quot;)
          Next
        %>
        </ul>
        </body></html>

        <!-- code declaration block -->
        <script runat=server>
          '*** becomes a custom field in page-derived class
          Private m_values As New ArrayList()
          '*** becomes a custom event in page-derived class
          Sub Page_Load(sender As Object, e As EventArgs)
            If Not Page.IsPostBack Then
              m_values.Add(quot;Bob Backerrachquot;)
              m_values.Add(quot;Mary Contraryquot;)
              m_values.Add(quot;Dirk Digglerquot;)
            End If
          End Sub
        </script>
                                                                         14
ASP.NET directives

•   ASP.NET supports several important page-level directives
     – @Page directive controls how the page file is compiled
     – @Page directive can take many different attributes
     – @Assembly directive replaces the /r command-line switch to
       VBC.EXE
     – @Import directive replaces the VB.NET Imports statement




                                                                    15
@Page Directives



                           <!-- MyPage4.aspx -->
                           <%@Page Language=quot;VBquot; Explicit=quot;Truequot; %>

                           <%@Assembly name=quot;MyLibraryquot; %>
Imports AcmeCorp
                           <%@Import namespace=quot;AcmeCorpquot; %>
'*** code goes here
                           <!-- code/content goes here -->



  vbc.exe /optionexplicit+ /r:MyLibrary.dll HashedNameForMyPage4.vb


          Directive Name                     Description
              @Page               Compilation and processing options
           @Assembly               Replaces the VBC.EXE /r: switch
             @Import           Replaces the VB.NET Imports statement




                                                                       16
@Page Directives

                    Name                          Description
                   Language            Programming language to use for <%

                    Buffer                     Response buffering

                ContentType            Default Content-Type header (MIME)

            EnableSessionState              Turns session state on/off

              EnableViewState                 Turns view state on/off

                      Src              Indicates source file for code-behind

                   Inherits            Indicates base class other than Page

                   ErrorPage            URL for unhandled exception page

                   Explicit                 Turns Option Explicit on/off

                    Strict                   Turns Option Strict on/off

                     Debug        Enables/disables compiling with debug symbols

                     Trace                   Enables/disables tracing

              CompilerOptions      Enabled passing switches directly to VBC.EXE


      <%@Page Language=quot;VBquot; Buffer=quot;truequot; Explicit=quot;Truequot; Strict=quot;Truequot; %>

                                                                                  17
Using a code-behind source file

•   ASP.NET provides various code-behind techniques promote a separation of
    code and HTML
     – Types inside a code-behind file are accessible from a .aspx file
     – Pre-compiled code-behind files are placed in the bin directory
     – Code-behind source files can compiled on demand using the Src
       attribute
     – Code-behind source files have extensions such as .vb or .cs
     – Compiling code-behind files on demand is useful during development
     – Compiling code-behind files on demand shouldn't be used in production




                                                                               18
ASP.NET code can be partitioned using code-behind features




 <%-- MyPage4.aspx --%>
 <%@ page language=quot;VBquot; src=quot;MyLibrary.vbquot; %>

 <%@ Import Namespace=quot;AcmeCorpquot; %>

 <html><body>
   <h3>Splitting code between a .aspx file and a .vb file</h3>
   This text was generated by MyPage3.aspx<br>
   <%
      Dim obj As New ContentGenerator
      Response.Write(obj.GetContent())
   %>
 </body></html>




                                                                 19
ASP.NET code used as code-behind for an ASP.NET page




 '*** source file: MyLibrary.vb
 Imports System

 Namespace AcmeCorp
   Public Class ContentGenerator
     Function GetContent() As String
       Return quot;This text was generated by MyLibrary.vbquot;
     End Function
   End Class
 End Namespace




                                                          20
web.config

•   ASP.NET configuration is controled by a XML-based file named
    web.config
     – web.config must be placed in IIS application's root directory
     – compilation section controls compiler stuff
     – httpRuntime section controls request execution
     – pages section controls how pages are compiled and run
     – Many other ASP.NET-specific section are available




                                                                       21
An example web.config file

  <?xml version=quot;1.0quot; encoding=quot;UTF-8quot; ?>

  <configuration>

    <system.web>

      <compilation debug=quot;truequot; explicit=quot;truequot; strict=quot;truequot;>
        <assemblies>
          <add assembly=quot;System.Runtime.Serialization.Formatters.Soapquot;/>
        </assemblies>
      </compilation>

      <httpRuntime
         executionTimeout=quot;90quot;
         maxRequestLength=quot;4096quot;
      />

      <pages
         buffer=quot;truequot;
         enableSessionState=quot;truequot;
         enableViewState=quot;truequot;
      />

    </system.web>

  </configuration>
                                                                           22
Creating a custom HTTP handler

• IHttpHandler defines the semantics for an object that will serve as
  the end point for an HTTP request in the ASP.NET framework
   – IHttpHandler is defined by ASP.NET in the System.Web
      namespace
   – Any IHttpHandler-compatible object can used as an ASP.NET
      handler
   – It's simple to write and configure a handler as a plug-compatible
      component
   – web.config file can be configured to dynamically load
      assembly/class
   – Use of .ashx files eliminates need to configure web.config file




                                                                         23
IHttpHandler is implemented by objects that service HTTP requests




       Namespace System.Web

          Public Interface IHttpHandler
            Sub ProcessRequest(context As HttpContext)
            ReadOnly Property IsReusable As Boolean
          End Interface

       End Namespace




                                                                    24
Classes that implement IHttpHandler are plug compatible

    '*** source file: MyLibrary1.vb
    '*** build target: MyLibrary1.dll

    Imports System.Web

    Public Class MyHandler1 : Implements IHttpHandler

      Sub ProcessRequest(context As HttpContext) _
          Implements IHttpHandler.ProcessRequest
        '*** return friendly message in body of HTTP response
        context.Response.Output.Write(quot;Hello worldquot;)
      End Sub

      ReadOnly Property IsReusable As Boolean _
               Implements IHttpHandler.IsReusable
        Return True
      End property

    End Class

    <?xml version=quot;1.0quot; encoding=quot;utf-8quot; ?>
    <configuration>
      <system.web>
        <httpHandlers>
          <add verb=quot;*quot;
               path=quot;*quot;
               type=quot;MyHandler1, MyLibrary1quot; />
        </httpHandlers>
      </system.web>
    </configuration>                                            25
Using a .ashx file


   <%@ webhandler language=quot;VBquot; class=quot;Class1quot; %>

   '*** everything from here down is sent directly to VBC.EXE

   Imports System.Web

   Public Class Class1 : Implements IHttpHandler

      Sub ProcessRequest(context As HttpContext) _
          Implements IHttpHandler.ProcessRequest
        context.Response.Output.Write(quot;Hello worldquot;)
      End Sub

      ReadOnly Property IsReusable As Boolean _
               Implements IHttpHandler.IsReusable
        Return True
      End property

   End Class

                                                                26
Debugging ASP.NET applications

•   ASP.NET provides extensive debugging support
     – compilation section in web.config must enabled debugging
    – You can use either Visual Studio .NET or DbgClr.exe
    – Choose Debug Processes from the Tools menu
    – Attach debugger to ASP.NET worker process ASPNET_WP.EXE
    – Open source files inside debugger and set breakpoints
    – Execute page by submitting request as usual with browser




                                                                  27
Creating HTML-based applications

•   ASP.NET is more than just ASP 4.0
     – Unlike ASP, ASP.NET is HTML-aware
     – Lots of internal Page class code dedicated to forms/control processing
     –   Code-behind techniques encourage better separation of code from HTML
     –   Extensible, server-side control architecture
     –   Server-side data binding model
     –   Form validation architecture




                                                                                28
The quot;Hello worldquot; WebForm example


<%@Page language=quot;VBquot; %>

<html><body>
  <form runat=quot;serverquot;>
    <p><ASP:Textbox id=quot;txtValue1quot; runat=quot;serverquot; /></p>
    <p><ASP:Textbox id=quot;txtValue2quot; runat=quot;serverquot; /></p>
    <p><ASP:Button text=quot;Add Numbersquot;
             runat=quot;serverquot; OnClick=quot;cmdAdd_OnClickquot; /> </p>
    <p><ASP:Textbox id=quot;txtValue3quot; runat=quot;serverquot; /></p>
  </form>
</body></html>

<script runat=quot;serverquot;>
  Sub cmdAdd_OnClick(sender As Object , e As System.EventArgs)
    Dim x, y As Integer
    x = CInt(txtValue1.Text)
    y = CInt(txtValue2.Text)
    txtValue3.Text = CStr(x + y)
  End Sub
</script>

                                                                 29
Using code-behind inheritance

•   An ASP.NET page can inherit from another custom Page-derived class
     – Code-behind inheritance allows you to remove all code from .aspx
       files
     – Your code goes into a custom class that inherits from the Page
       class
     – Custom page class goes into a separate source file
     – The .aspx file uses Inherits attribute inside @Page directive
     – Separation of code and HTML (i.e. presentation) significantly
       improve the maintainability of an HTML-based application




                                                                          30
<%@Page Inherits=quot;MyPageClassquot; Src=quot;MyLibrary.vbquot; %>

<html><body>
  <form runat=quot;serverquot;>
    <p><ASP:Textbox id=quot;txtValue1quot; runat=quot;serverquot; /></p>
    <p><ASP:Textbox id=quot;txtValue2quot; runat=quot;serverquot; /></p>
    <p><ASP:Button id=quot;cmdAddquot; text=quot;Add Numbersquot;
            runat=quot;serverquot; OnClick=quot;cmdAdd_OnClickquot; /> </p>
    <p><ASP:Textbox id=quot;txtValue3quot; runat=quot;serverquot; /></p>
  </form>
</body></html>

Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls

Public Class MyPageClass : Inherits Page

 Protected   txtValue1 As Textbox
 Protected   txtValue2 As Textbox
 Protected   txtValue3 As Textbox
 Protected   WithEvents cmdAdd As Button

 Sub cmdAdd_OnClick(sender As Object, e As System.EventArgs)
   Dim x, y As Integer
   x = CInt(txtValue1.Text)
   y = CInt(txtValue2.Text)
   txtValue3.Text = CStr(x + y)
 End Sub

End Class                                                      31
User versus Programmatic Interfaces

•   ASP.NET applications may expose both user and programmatic
    interfaces
      – User interface expressed through HTML
      – Handled by System.Web.UI.*
      – Programmatic interfaces exposed via XML/SOAP
      – Programmatic interface handled by System.Web.Services.*




                                                                  32
Web Methods

•   Web services are .NET methods marked with the WebMethod attribute
     – Authored like any other method you might write, with a file
       extension of .asmx
     – ASP.NET takes care of mapping incoming HTTP requests onto
       calls on your object
     – .NET provides proxy classes on the client side that make calling
       web services as trivial as calling other functions
     – Client-side proxy takes care of generating HTTP request to server,
       and parsing response as return value




                                                                            33
Web Method within a .asmx file

     <%@ WebService language=quot;C#quot; Class=quot;Calculatorquot;%>

     using System;
     using System.Web.Services;

     public class Calculator : WebService {

         [ WebMethod ]
         public int Add( int x, int y ) {
           return x + y;
         }

         [ WebMethod ]
         public int Multiply( int x, int y ) {
           return x * y;
         }
     }


                                                         34

Contenu connexe

Tendances (20)

Servlet
Servlet Servlet
Servlet
 
Servlets
ServletsServlets
Servlets
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jsp
 
Servlets
ServletsServlets
Servlets
 
Java servlet technology
Java servlet technologyJava servlet technology
Java servlet technology
 
Java Servlet
Java Servlet Java Servlet
Java Servlet
 
Servlets
ServletsServlets
Servlets
 
Jsp sasidhar
Jsp sasidharJsp sasidhar
Jsp sasidhar
 
Listeners and filters in servlet
Listeners and filters in servletListeners and filters in servlet
Listeners and filters in servlet
 
java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technology
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
JAVA Servlets
JAVA ServletsJAVA Servlets
JAVA Servlets
 
Java servlets
Java servletsJava servlets
Java servlets
 
1 java servlets and jsp
1   java servlets and jsp1   java servlets and jsp
1 java servlets and jsp
 
Servlets
ServletsServlets
Servlets
 
Java Servlets & JSP
Java Servlets & JSPJava Servlets & JSP
Java Servlets & JSP
 
Servlets
ServletsServlets
Servlets
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 

Similaire à Aspdotnet

SynapseIndia dotnet development ajax client library
SynapseIndia dotnet development ajax client librarySynapseIndia dotnet development ajax client library
SynapseIndia dotnet development ajax client librarySynapseindiappsdevelopment
 
Understanding ASP.NET Under The Cover - Miguel A. Castro
Understanding ASP.NET Under The Cover - Miguel A. CastroUnderstanding ASP.NET Under The Cover - Miguel A. Castro
Understanding ASP.NET Under The Cover - Miguel A. CastroMohammad Tayseer
 
Web container and Apache Tomcat
Web container and Apache TomcatWeb container and Apache Tomcat
Web container and Apache TomcatAuwal Amshi
 
C sharp and asp.net interview questions
C sharp and asp.net interview questionsC sharp and asp.net interview questions
C sharp and asp.net interview questionsAkhil Mittal
 
Introduction to asp.net
Introduction to asp.netIntroduction to asp.net
Introduction to asp.netneeta1995
 
10 tips to make your ASP.NET Apps Faster
10 tips to make your ASP.NET Apps Faster10 tips to make your ASP.NET Apps Faster
10 tips to make your ASP.NET Apps FasterBrij Mishra
 
ASP, ASP.NET, JSP, COM/DCOM
ASP, ASP.NET, JSP, COM/DCOMASP, ASP.NET, JSP, COM/DCOM
ASP, ASP.NET, JSP, COM/DCOMAashish Jain
 
Asynchronous reading and writing http r equest
Asynchronous reading and writing http r equestAsynchronous reading and writing http r equest
Asynchronous reading and writing http r equestPragyanshis Patnaik
 
Programming web application
Programming web applicationProgramming web application
Programming web applicationaspnet123
 
Asp Net (FT Preasen Revankar)
Asp Net   (FT  Preasen Revankar)Asp Net   (FT  Preasen Revankar)
Asp Net (FT Preasen Revankar)Fafadia Tech
 
Dot Net Framework
Dot Net FrameworkDot Net Framework
Dot Net Frameworkssa2010
 
Skillwise - Advanced web application development
Skillwise - Advanced web application developmentSkillwise - Advanced web application development
Skillwise - Advanced web application developmentSkillwise Group
 

Similaire à Aspdotnet (20)

ASP.NET lecture 8
ASP.NET lecture 8ASP.NET lecture 8
ASP.NET lecture 8
 
SynapseIndia dotnet development ajax client library
SynapseIndia dotnet development ajax client librarySynapseIndia dotnet development ajax client library
SynapseIndia dotnet development ajax client library
 
Understanding ASP.NET Under The Cover - Miguel A. Castro
Understanding ASP.NET Under The Cover - Miguel A. CastroUnderstanding ASP.NET Under The Cover - Miguel A. Castro
Understanding ASP.NET Under The Cover - Miguel A. Castro
 
Asp.net
Asp.netAsp.net
Asp.net
 
Asp
AspAsp
Asp
 
Web container and Apache Tomcat
Web container and Apache TomcatWeb container and Apache Tomcat
Web container and Apache Tomcat
 
15th june
15th june15th june
15th june
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
C sharp and asp.net interview questions
C sharp and asp.net interview questionsC sharp and asp.net interview questions
C sharp and asp.net interview questions
 
Lecture2
Lecture2Lecture2
Lecture2
 
Introduction to asp.net
Introduction to asp.netIntroduction to asp.net
Introduction to asp.net
 
Async Programming in C# 5
Async Programming in C# 5Async Programming in C# 5
Async Programming in C# 5
 
10 tips to make your ASP.NET Apps Faster
10 tips to make your ASP.NET Apps Faster10 tips to make your ASP.NET Apps Faster
10 tips to make your ASP.NET Apps Faster
 
Introduction to asp
Introduction to aspIntroduction to asp
Introduction to asp
 
ASP, ASP.NET, JSP, COM/DCOM
ASP, ASP.NET, JSP, COM/DCOMASP, ASP.NET, JSP, COM/DCOM
ASP, ASP.NET, JSP, COM/DCOM
 
Asynchronous reading and writing http r equest
Asynchronous reading and writing http r equestAsynchronous reading and writing http r equest
Asynchronous reading and writing http r equest
 
Programming web application
Programming web applicationProgramming web application
Programming web application
 
Asp Net (FT Preasen Revankar)
Asp Net   (FT  Preasen Revankar)Asp Net   (FT  Preasen Revankar)
Asp Net (FT Preasen Revankar)
 
Dot Net Framework
Dot Net FrameworkDot Net Framework
Dot Net Framework
 
Skillwise - Advanced web application development
Skillwise - Advanced web application developmentSkillwise - Advanced web application development
Skillwise - Advanced web application development
 

Plus de Adil Jafri

Csajsp Chapter5
Csajsp Chapter5Csajsp Chapter5
Csajsp Chapter5Adil Jafri
 
Programming Asp Net Bible
Programming Asp Net BibleProgramming Asp Net Bible
Programming Asp Net BibleAdil Jafri
 
Network Programming Clients
Network Programming ClientsNetwork Programming Clients
Network Programming ClientsAdil Jafri
 
Ta Javaserverside Eran Toch
Ta Javaserverside Eran TochTa Javaserverside Eran Toch
Ta Javaserverside Eran TochAdil Jafri
 
Csajsp Chapter10
Csajsp Chapter10Csajsp Chapter10
Csajsp Chapter10Adil Jafri
 
Flashmx Tutorials
Flashmx TutorialsFlashmx Tutorials
Flashmx TutorialsAdil Jafri
 
Java For The Web With Servlets%2cjsp%2cand Ejb
Java For The Web With Servlets%2cjsp%2cand EjbJava For The Web With Servlets%2cjsp%2cand Ejb
Java For The Web With Servlets%2cjsp%2cand EjbAdil Jafri
 
Csajsp Chapter12
Csajsp Chapter12Csajsp Chapter12
Csajsp Chapter12Adil Jafri
 
Flash Tutorial
Flash TutorialFlash Tutorial
Flash TutorialAdil Jafri
 

Plus de Adil Jafri (20)

Csajsp Chapter5
Csajsp Chapter5Csajsp Chapter5
Csajsp Chapter5
 
Php How To
Php How ToPhp How To
Php How To
 
Php How To
Php How ToPhp How To
Php How To
 
Owl Clock
Owl ClockOwl Clock
Owl Clock
 
Phpcodebook
PhpcodebookPhpcodebook
Phpcodebook
 
Phpcodebook
PhpcodebookPhpcodebook
Phpcodebook
 
Programming Asp Net Bible
Programming Asp Net BibleProgramming Asp Net Bible
Programming Asp Net Bible
 
Tcpip Intro
Tcpip IntroTcpip Intro
Tcpip Intro
 
Network Programming Clients
Network Programming ClientsNetwork Programming Clients
Network Programming Clients
 
Jsp Tutorial
Jsp TutorialJsp Tutorial
Jsp Tutorial
 
Ta Javaserverside Eran Toch
Ta Javaserverside Eran TochTa Javaserverside Eran Toch
Ta Javaserverside Eran Toch
 
Csajsp Chapter10
Csajsp Chapter10Csajsp Chapter10
Csajsp Chapter10
 
Javascript
JavascriptJavascript
Javascript
 
Flashmx Tutorials
Flashmx TutorialsFlashmx Tutorials
Flashmx Tutorials
 
Java For The Web With Servlets%2cjsp%2cand Ejb
Java For The Web With Servlets%2cjsp%2cand EjbJava For The Web With Servlets%2cjsp%2cand Ejb
Java For The Web With Servlets%2cjsp%2cand Ejb
 
Html Css
Html CssHtml Css
Html Css
 
Digwc
DigwcDigwc
Digwc
 
Csajsp Chapter12
Csajsp Chapter12Csajsp Chapter12
Csajsp Chapter12
 
Html Frames
Html FramesHtml Frames
Html Frames
 
Flash Tutorial
Flash TutorialFlash Tutorial
Flash Tutorial
 

Dernier

Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 

Dernier (20)

Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 

Aspdotnet

  • 2. ASP.NET • ASP.NET is a managed framework that facilitates building server-side applications based on HTTP, HTML, XML and SOAP. To .NET developers, ASP.NET is a platform that provides one-stop shopping for all application development that requires the processing of HTTP requests. 2
  • 3. A platform on a platform • ASP.NET is a managed framework that facilitates building server-side applications based on HTTP, HTML, XML and SOAP – ASP.NET supports building HTML-based applications with Web forms, server-side controls and data binding – ASP.NET supports building non-visual request handlers and Web services W eb B row ser HTM L HTTP Runtime (IIS/ISAPI) W e b S e r v ic e C lie n t S ys te m .W e b (A S P .N E T ) XM L M u ltim e d ia C lie n t M P 3 /P N G /W M V 3
  • 4. A new and better version of ASP • ASP.NET is a much improved replacement for original ASP framework – All ASP.NET code is fully compiled prior to execution – ASP.NET doesn't require the use of scripting languages – ASP.NET allows for total separation of code from HTML – ASP.NET state management works in a Web farm environment 4
  • 5. ASP.NET Internals • ASP.NET uses a new CLR-based framework to replace ISAPI/ASP architecture – ASP.NET requests are initially handled by the HTTP runtime of IIS – ASP.NET ISAPI extension DLL redirects requests to ASP.NET worker process HTTP request *.ashx ISAPI ASPNET_ISAPI.DLL ASP.NET *.aspx Extension ISAPI extension *.asmx for ASP.NET Named Pipes pipeline *.disco Manager *.soap INETINFO.EXE ASPNET_WP.EXE HTTP runtime provided by IIS ASP.NET Worker Process 5
  • 6. ASP.NET Internals • Requests are process in the quot;HTTP pipelinequot; inside ASP.NET worker process – Pipeline always contains HttpRuntime class – Pipeline always contains exactly one HTTP handler object – Modules are interceptors that can (optionally) be placed in pipeline – HttpContext is a valuable class accessible from anywhere in pipeline ASP.NET worker thread 1 HttpRuntime HTTP Handler Module 1 Module 2 Class MyPage.aspx ASP.NET worker thread 2 HttpRuntime HTTP Handler Module 1 Module 2 Class MyHandler.ashx ASP.NET worker thread 3 HttpRuntime HTTP Handler Module 1 Module 2 Class Class1 from MyLibrary.dll ASP.NET Worker Process ASPNET_WP.EXE 6
  • 7. HttpContext Properties Type Name Description HttpContext Current (Shared) Context for request currently in progress HttpApplicationState Application Appliction-wide property-bag HttpApplication ApplicationInstance Application context (modules) HttpSessionState Session Per-client session state HttpRequest Request The HTTP request HttpResponse Response The HTTP response IPrincipal User The security ID of the caller IHttpHandler Handler The handler dispatched to the call IDictionary Items Per-request property-bag HttpServerUtility Server URL Cracking/Sub-handlers Exception Error The 1st error to occur during processing 7
  • 8. Programming against the HttpContext object Imports System.Web Public Module PipelineUtilities Sub SayHello() Dim ctx As HttpContext = HttpContext.Current If ctx Is Nothing '*** executing outside the scope of HTTP pipeline Else ctx.Response.Write(quot;Hello, quot;) Dim name As String = ctx.Request.QueryString(quot;namequot;) ctx.Response.Output.WriteLine(name) End If End Sub End Module 8
  • 9. Integrated compilation support • ASP.NET provides integrated compilation support to build source files into DLLs in just-in-time fashion – Auto-compilation supported for .aspx, .ascx, .asmx and .ashx files – The generated assembly is stored in subdirectory off of CodeGen directory – ASP.NET automatically references all assemblies in bin directory – ASP.NET automatically references several commonly-used .NET assemblies – Other assemblies can be referenced through custom configuration – Shadow-copying allows DLLs to be overwritten while application is running 9
  • 10. Hello, World using VB.NET in an ASP.NET page <%-- MyPage1.aspx --%> <%@ page language=quot;VBquot; %> <html><body> <h3>My Page</h3> This page contains boring static content and <% Dim s As String = quot;<i>exciting dynamic content</i>quot; Response.Write(s) %> </body></html> 10
  • 11. System.Web.UI.Page • An .aspx file is transformed into a class that inherits from Page class – Page class provides HTTP handler support – Page class members are accessible from anywhere inside .aspx file – Much of Page class dedicated to generation of HTML – Static HTML in .aspx file becomes part of page's Render method – Code render blocks in .aspx file become part of page's Render method – Members defined in code declaration blocks become members of page class – WebForms and server-side controls build on top of Page class architecture 11
  • 12. Using reflection from an ASP.NET page <%@ page language=quot;VBquot; %> <html><body> <% '*** note that this variable refers to subtype of Page Dim MyType As String = Me.GetType().ToString() Dim MyDadsType As String = Me.GetType().BaseType.ToString() '*** note that Response is a property of Page Me.Response.Write(quot;page type: quot; & MyType & quot;<br>quot;) Me.Response.Write(quot;page's base type: quot; & MyDadsType & quot;<br>quot;) %> </body></html> 12
  • 13. System.Web.UI.Page Imports System.Web.UI Class System.Web.UI.Page '*** functionality similar to what's in ASP ReadOnly Property Application As HttpApplicationState ReadOnly Property Session As HttpSessionState ReadOnly Property Request As HttpRequest ReadOnly Property Response As HttpResponse ReadOnly Property Server As HttpServerUtility Property Buffer As Boolean Function MapPath(virtualPath As String) As String Sub Navigate(url As String) '*** functionality new to ASP.NET Property ClientTarget As ClientTarget ReadOnly User As IPrincipal ReadOnly Property IsPostBack As Boolean Protected Overridable Sub Render(writer As HtmlTextWriter) Event Load As EventHandler End Class 13
  • 14. Sample aspx file customizing Page <!-- MyPage2.aspx --> <%@ Page Language=quot;VBquot; %> <html><body> <h2>Customer list</h2> <ul> <% '*** code render block becomes part of Render method Dim i As Integer For i = 0 to (m_values.Count - 1) Response.Write(quot;<li>quot; & m_values(i).ToString & quot;</li>quot;) Next %> </ul> </body></html> <!-- code declaration block --> <script runat=server> '*** becomes a custom field in page-derived class Private m_values As New ArrayList() '*** becomes a custom event in page-derived class Sub Page_Load(sender As Object, e As EventArgs) If Not Page.IsPostBack Then m_values.Add(quot;Bob Backerrachquot;) m_values.Add(quot;Mary Contraryquot;) m_values.Add(quot;Dirk Digglerquot;) End If End Sub </script> 14
  • 15. ASP.NET directives • ASP.NET supports several important page-level directives – @Page directive controls how the page file is compiled – @Page directive can take many different attributes – @Assembly directive replaces the /r command-line switch to VBC.EXE – @Import directive replaces the VB.NET Imports statement 15
  • 16. @Page Directives <!-- MyPage4.aspx --> <%@Page Language=quot;VBquot; Explicit=quot;Truequot; %> <%@Assembly name=quot;MyLibraryquot; %> Imports AcmeCorp <%@Import namespace=quot;AcmeCorpquot; %> '*** code goes here <!-- code/content goes here --> vbc.exe /optionexplicit+ /r:MyLibrary.dll HashedNameForMyPage4.vb Directive Name Description @Page Compilation and processing options @Assembly Replaces the VBC.EXE /r: switch @Import Replaces the VB.NET Imports statement 16
  • 17. @Page Directives Name Description Language Programming language to use for <% Buffer Response buffering ContentType Default Content-Type header (MIME) EnableSessionState Turns session state on/off EnableViewState Turns view state on/off Src Indicates source file for code-behind Inherits Indicates base class other than Page ErrorPage URL for unhandled exception page Explicit Turns Option Explicit on/off Strict Turns Option Strict on/off Debug Enables/disables compiling with debug symbols Trace Enables/disables tracing CompilerOptions Enabled passing switches directly to VBC.EXE <%@Page Language=quot;VBquot; Buffer=quot;truequot; Explicit=quot;Truequot; Strict=quot;Truequot; %> 17
  • 18. Using a code-behind source file • ASP.NET provides various code-behind techniques promote a separation of code and HTML – Types inside a code-behind file are accessible from a .aspx file – Pre-compiled code-behind files are placed in the bin directory – Code-behind source files can compiled on demand using the Src attribute – Code-behind source files have extensions such as .vb or .cs – Compiling code-behind files on demand is useful during development – Compiling code-behind files on demand shouldn't be used in production 18
  • 19. ASP.NET code can be partitioned using code-behind features <%-- MyPage4.aspx --%> <%@ page language=quot;VBquot; src=quot;MyLibrary.vbquot; %> <%@ Import Namespace=quot;AcmeCorpquot; %> <html><body> <h3>Splitting code between a .aspx file and a .vb file</h3> This text was generated by MyPage3.aspx<br> <% Dim obj As New ContentGenerator Response.Write(obj.GetContent()) %> </body></html> 19
  • 20. ASP.NET code used as code-behind for an ASP.NET page '*** source file: MyLibrary.vb Imports System Namespace AcmeCorp Public Class ContentGenerator Function GetContent() As String Return quot;This text was generated by MyLibrary.vbquot; End Function End Class End Namespace 20
  • 21. web.config • ASP.NET configuration is controled by a XML-based file named web.config – web.config must be placed in IIS application's root directory – compilation section controls compiler stuff – httpRuntime section controls request execution – pages section controls how pages are compiled and run – Many other ASP.NET-specific section are available 21
  • 22. An example web.config file <?xml version=quot;1.0quot; encoding=quot;UTF-8quot; ?> <configuration> <system.web> <compilation debug=quot;truequot; explicit=quot;truequot; strict=quot;truequot;> <assemblies> <add assembly=quot;System.Runtime.Serialization.Formatters.Soapquot;/> </assemblies> </compilation> <httpRuntime executionTimeout=quot;90quot; maxRequestLength=quot;4096quot; /> <pages buffer=quot;truequot; enableSessionState=quot;truequot; enableViewState=quot;truequot; /> </system.web> </configuration> 22
  • 23. Creating a custom HTTP handler • IHttpHandler defines the semantics for an object that will serve as the end point for an HTTP request in the ASP.NET framework – IHttpHandler is defined by ASP.NET in the System.Web namespace – Any IHttpHandler-compatible object can used as an ASP.NET handler – It's simple to write and configure a handler as a plug-compatible component – web.config file can be configured to dynamically load assembly/class – Use of .ashx files eliminates need to configure web.config file 23
  • 24. IHttpHandler is implemented by objects that service HTTP requests Namespace System.Web Public Interface IHttpHandler Sub ProcessRequest(context As HttpContext) ReadOnly Property IsReusable As Boolean End Interface End Namespace 24
  • 25. Classes that implement IHttpHandler are plug compatible '*** source file: MyLibrary1.vb '*** build target: MyLibrary1.dll Imports System.Web Public Class MyHandler1 : Implements IHttpHandler Sub ProcessRequest(context As HttpContext) _ Implements IHttpHandler.ProcessRequest '*** return friendly message in body of HTTP response context.Response.Output.Write(quot;Hello worldquot;) End Sub ReadOnly Property IsReusable As Boolean _ Implements IHttpHandler.IsReusable Return True End property End Class <?xml version=quot;1.0quot; encoding=quot;utf-8quot; ?> <configuration> <system.web> <httpHandlers> <add verb=quot;*quot; path=quot;*quot; type=quot;MyHandler1, MyLibrary1quot; /> </httpHandlers> </system.web> </configuration> 25
  • 26. Using a .ashx file <%@ webhandler language=quot;VBquot; class=quot;Class1quot; %> '*** everything from here down is sent directly to VBC.EXE Imports System.Web Public Class Class1 : Implements IHttpHandler Sub ProcessRequest(context As HttpContext) _ Implements IHttpHandler.ProcessRequest context.Response.Output.Write(quot;Hello worldquot;) End Sub ReadOnly Property IsReusable As Boolean _ Implements IHttpHandler.IsReusable Return True End property End Class 26
  • 27. Debugging ASP.NET applications • ASP.NET provides extensive debugging support – compilation section in web.config must enabled debugging – You can use either Visual Studio .NET or DbgClr.exe – Choose Debug Processes from the Tools menu – Attach debugger to ASP.NET worker process ASPNET_WP.EXE – Open source files inside debugger and set breakpoints – Execute page by submitting request as usual with browser 27
  • 28. Creating HTML-based applications • ASP.NET is more than just ASP 4.0 – Unlike ASP, ASP.NET is HTML-aware – Lots of internal Page class code dedicated to forms/control processing – Code-behind techniques encourage better separation of code from HTML – Extensible, server-side control architecture – Server-side data binding model – Form validation architecture 28
  • 29. The quot;Hello worldquot; WebForm example <%@Page language=quot;VBquot; %> <html><body> <form runat=quot;serverquot;> <p><ASP:Textbox id=quot;txtValue1quot; runat=quot;serverquot; /></p> <p><ASP:Textbox id=quot;txtValue2quot; runat=quot;serverquot; /></p> <p><ASP:Button text=quot;Add Numbersquot; runat=quot;serverquot; OnClick=quot;cmdAdd_OnClickquot; /> </p> <p><ASP:Textbox id=quot;txtValue3quot; runat=quot;serverquot; /></p> </form> </body></html> <script runat=quot;serverquot;> Sub cmdAdd_OnClick(sender As Object , e As System.EventArgs) Dim x, y As Integer x = CInt(txtValue1.Text) y = CInt(txtValue2.Text) txtValue3.Text = CStr(x + y) End Sub </script> 29
  • 30. Using code-behind inheritance • An ASP.NET page can inherit from another custom Page-derived class – Code-behind inheritance allows you to remove all code from .aspx files – Your code goes into a custom class that inherits from the Page class – Custom page class goes into a separate source file – The .aspx file uses Inherits attribute inside @Page directive – Separation of code and HTML (i.e. presentation) significantly improve the maintainability of an HTML-based application 30
  • 31. <%@Page Inherits=quot;MyPageClassquot; Src=quot;MyLibrary.vbquot; %> <html><body> <form runat=quot;serverquot;> <p><ASP:Textbox id=quot;txtValue1quot; runat=quot;serverquot; /></p> <p><ASP:Textbox id=quot;txtValue2quot; runat=quot;serverquot; /></p> <p><ASP:Button id=quot;cmdAddquot; text=quot;Add Numbersquot; runat=quot;serverquot; OnClick=quot;cmdAdd_OnClickquot; /> </p> <p><ASP:Textbox id=quot;txtValue3quot; runat=quot;serverquot; /></p> </form> </body></html> Imports System Imports System.Web.UI Imports System.Web.UI.WebControls Public Class MyPageClass : Inherits Page Protected txtValue1 As Textbox Protected txtValue2 As Textbox Protected txtValue3 As Textbox Protected WithEvents cmdAdd As Button Sub cmdAdd_OnClick(sender As Object, e As System.EventArgs) Dim x, y As Integer x = CInt(txtValue1.Text) y = CInt(txtValue2.Text) txtValue3.Text = CStr(x + y) End Sub End Class 31
  • 32. User versus Programmatic Interfaces • ASP.NET applications may expose both user and programmatic interfaces – User interface expressed through HTML – Handled by System.Web.UI.* – Programmatic interfaces exposed via XML/SOAP – Programmatic interface handled by System.Web.Services.* 32
  • 33. Web Methods • Web services are .NET methods marked with the WebMethod attribute – Authored like any other method you might write, with a file extension of .asmx – ASP.NET takes care of mapping incoming HTTP requests onto calls on your object – .NET provides proxy classes on the client side that make calling web services as trivial as calling other functions – Client-side proxy takes care of generating HTTP request to server, and parsing response as return value 33
  • 34. Web Method within a .asmx file <%@ WebService language=quot;C#quot; Class=quot;Calculatorquot;%> using System; using System.Web.Services; public class Calculator : WebService { [ WebMethod ] public int Add( int x, int y ) { return x + y; } [ WebMethod ] public int Multiply( int x, int y ) { return x * y; } } 34