ASP.NET Architecture - PowerPoint PPT Presentation


PPT – ASP.NET Architecture PowerPoint presentation | free to download - id: 9004a-NDAwO


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation

ASP.NET Architecture


Accepts a costume order. ... The costume information is retrieved from a file and stored in a sorted list. ... to store the costume and order data between ... – PowerPoint PPT presentation

Number of Views:62
Avg rating:3.0/5.0
Slides: 37
Provided by: kelly100
Learn more at:


Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: ASP.NET Architecture

ASP.NET Architecture

Halloween Store application
The Shopping Cart page of the Halloween Store
Components of a web application
Server computer
Client computer
Web server
Web browser
  • Web applications are a type of client/server
    application, where a user at a client computer
    accesses an application at a server computer.
  • Client and server computers are connected via the

Hardware and software components for web
  • At the client computer, the user works with a Web
    browser, such as Internet Explorer or FireFox,
    that provides the user interface for the
  • The application runs on the server computer under
    the control of Web server software. For ASP.NET
    web applications, the server must run Microsofts
    Web server, Internet Information Services (IIS).
  • The server computer typically also runs a
    database management system, or DBMS, that
    provides access to information stored in a
    database. To improve performance, the DBMS can be
    run on a separate server computer.

Hardware and software components for Web
applications (cont.)
  • The user interface for a Web application is
    implemented as a series of Web pages that are
    displayed in the web browser.
  • Each web page is defined by a Web form using
    HTML, or Hypertext Markup Language, which is a
    standardized set of markup tags.
  • The Web browser and Web server exchange
    information using HTTP, or Hypertext Transfer

How a Web server processes static web pages
HTTP request
HTML file
HTML file
HTTP response
  • A static web page is an HTML document that is the
    same each time its viewed. It doesnt change in
    response to user input.
  • Static web pages are usually simple HTML files
    that are stored on the Web server with a file
    extension of .htm or .html.
  • When a browser requests a static web page, the
    web server retrieves the file from disk and sends
    it back to the browser.

How static web pages work
  • A web browser requests a page from a web server
    by sending the server an HTTP request message.
  • The HTTP request includes, the name of the HTML
    file being requested and the Internet address of
    both the browser and the Web server.
  • A user working with a browser can initiate an
    HTTP request in several ways. One way is to type
    the address of a web page, called a URL, or
    Uniform Resource Locator, into the browsers
    address area and press Enter. Another way is to
    click a link that refers to a web page.
  • A web server replies to an HTTP request by
    sending a message known as an HTTP response back
    to the browser.
  • The HTTP response contains the addresses of the
    browser and the server as well as the HTML
    document thats being returned.

Processing dynamic pages
HTTP request
Web server
Application server
HTTP response
Web application
How dynamic web pages work
  • A dynamic web page is an HTML document generated
    by a web application. Often, the Web page changes
    according to information sent to the Web
    application by the browser.
  • When a Web server receives a request for a
    dynamic web page, the server passes the request
    to an application server.
  • The application server executes the Web
    application, which generates an HTML document.
    This document is returned to the application
    server, which passes it back to the web server.
    The Web server, in turn, sends the document back
    to the browser.
  • After the page is displayed, the user can
    interact with it using its controls. Some of
    those controls let the user post the page back to
    the server, so its processed again using the
    data the user entered.

Dynamic Web Pages
  • To determine what application server is used to
    process a request, the Web server looks up the
    extension of the requested file in a list of
    application mappings.
  • Each application mapping specifies which
    application should be run to process files with
    that extension.
  • If the file extension is aspx, the request is
    passed to ASP.NET.
  • If the file extension isnt in the list of
    application mappings, the requested file is
    returned to the browser without any processing.
  • The process that begins with the user requesting
    a web page and ends with the server sending a
    response back to the client is called a round
  • After a web application generates an HTML
    document, it ends. Then, unless the data the
    application contains is specifically saved, that
    data is lost.

Application state
  • State refers to the current status of the
    properties, variables, and other data maintained
    by an application for a single user.
  • The application must maintain a separate state
    for each user currently accessing the
  • HTTP is a stateless protocol
  • It doesnt keep track of state between round
  • Once a browser makes a request and receives a
    response, the application terminates and its
    state is lost

Tracking state in web applications
First HTTP request
The browser requests a
Web server
First HTTP response
The server returns the
requested page and the
Web server
application ends.
Next HTTP request
The browser requests another
page. The server has no way
to associate the browser with
its previous request.
Web server
Features to maintain state
  • ASP.NET uses view state to maintain the value of
    form control properties that the application
    changes between executions of the application.
    View state is implemented by default.
  • When a user starts a new session, ASP.NET creates
    a session state object. It contains a session ID
    thats passed from the server to the browser and
    back again so that the server can associate the
    browser with an existing session. To maintain
    session state, you can add program values to the
    session state object. Then, those values are
    maintained between executions of the application.
  • When an application begins, ASP.NET creates an
    application state object. To maintain application
    state, you can add program values to the
    application state object. These values are
    available to all users of the application and are
    maintained until the application ends.

The Costume page after an order is entered
The Confirmation page
A simple application
  • Accepts a costume order.
  • To enter an order, the user selects a costume
    from the drop-down list on the Costume page,
    enters a quantity, and clicks on the Order
    Costume button. Then, the order is written to a
    file and the Confirmation page is displayed.
  • The costume information is retrieved from a file
    and stored in a sorted list. The sorted list is
    used to load the drop-down list. Then, when the
    user selects a costume, the price of that costume
    is retrieved from the sorted list and displayed
    on the form.
  • This application uses view state to maintain the
    items in the drop-down list when the user posts
    the page to the server by selecting a costume.
  • This application uses session state to store the
    costume and order data between executions.

The aspx code for the Costume form
  • lt_at_ Page LanguageC" AutoEventWireup"false"
    Codebehind"Costume.aspx.cs" Inherits"CostumeStor
  • ltHTMLgt
  • ltHEADgt
  • lttitlegtCostumelt/titlegt
  • lt/HEADgt
  • ltbody MS_POSITIONING"GridLayout"gt
  • ltform id"Form1" method"post"
  • ltaspimage id"Image1"
    style"Z-INDEX 107 LEFT 9px
  • POSITION absolute TOP 9px"
  • ImageUrl"banner.jpg"gtlt/aspimage
  • ltasplabel id"Label1"
    style"Z-INDEX 101 LEFT 10px
  • POSITION absolute TOP 122px"
  • Costumelt/asplabelgt
  • ltaspdropdownlist id"ddlCostumes"
    style"Z-INDEX 102
  • LEFT 82px POSITION absolute
    TOP 124px"
  • runat"server" Width"152px"
  • lt/aspdropdownlistgt
  • ltasplabel id"Label2"
    style"Z-INDEX 109 LEFT 10px

The aspx code for the Costume form (cont.)
  • POSITION absolute TOP 156px"
  • ltasplabel id"Label3"
    style"Z-INDEX 105 LEFT 10px
  • POSITION absolute TOP 189px"
  • Quantitylt/asplabelgt
  • ltasptextbox id"txtQuantity"
    style"Z-INDEX 104
  • LEFT 82px POSITION absolute
    TOP 189px"
  • runat"server"
  • ltasprequiredfieldvalidator
  • style"Z-INDEX 106 LEFT
    134px POSITION absolute
  • TOP 192px" runat"server"
  • ErrorMessage"You must enter a
  • ControlToValidate"txtQuantity"gt
  • lt/asprequiredfieldvalidatorgt
  • ltaspcomparevalidator
    id"CompareValidator1" style"Z-INDEX 108
  • LEFT 299px POSITION absolute
    TOP 192px" runat"server"
  • ErrorMessage"Quantity must be
    greater than 0."
  • ControlToValidate"txtQuantity"
  • Type"Integer"
  • ltaspbutton id"btnOrder"
    style"Z-INDEX 103 LEFT 10px

The aspx code for the Confirmation form
  • lt_at_ Page LanguageC" AutoEventWireup"false"Cod
    ebehind"Confirmation.aspx.cs" Inherits"CostumeSt
  • ltHTMLgt
  • ltHEADgt
  • lttitlegtConfirmationlt/titlegt
  • lt/HEADgt
  • ltbody MS_POSITIONING"GridLayout"gt
  • ltform id"Form1" method"post"
  • ltaspImage id"Image1"
    style"Z-INDEX 105 LEFT 8px
  • POSITION absolute TOP 8px"
  • ImageUrl"banner.jpg"gtlt/aspImage
  • ltaspLabel id"lblCostume"
    style"Z-INDEX 102 LEFT 9px
  • POSITION absolute TOP 128px"
  • runat"server"gtlt/aspLabelgt
  • ltaspbutton id"btnReturn"
    style"Z-INDEX 101 LEFT 9px
  • POSITION absolute TOP 214px"
  • Text"Return to Order
  • lt/formgt
  • lt/bodygt

The aspx code for the web forms
  • An aspx file defines an HTML document.
  • The first line of the HTML document is a Page
    directive that specifies the ASP.NET options.
  • The Codebehind option names the file that
    contains the C code for the page. This option is
    used by Visual Studio to associate the page with
    the class that contains the C code for the page.
  • The Inherits option names the page class that the
    page inherits at runtime. This class is part of
    the DLL file thats created when you compile the
  • The rest of the aspx file contains the HTML that
    determines how the page will appear in the
    browser. The HTML can include standard HTML tags
    and special ASP.NET tags. The ASP.NET tags begin
    with asp and define ASP.NET Web Server controls.

The aspx code for the web forms (cont.)
  • The Web Server controls are implemented by
    classes that are defined by the .NET Framework.
    ASP.NET renders these controls to standard HTML
    so the controls can be displayed in the browser.
  • The runat"server" attribute that appears in the
    form and asp tags indicates that the form and its
    controls are to be processed at the server by

The code for the Costume form
  • public class Costume System.Web.UI.Page
  • NameValueCollection costumes
  • void Page_Load(Object sender, System.EventArgs
  • GetCostumes()
  • if (!IsPostBack)
  • LoadCostumeDropDownList()
  • lblPrice.Text costumesddlCostumes.Selec
  • private void GetCostumes()
  • if (Session"Costumes null)
  • costumes OrdersDB.GetCostumes()
  • Session"Costumes costumes
  • else
  • costumes Session"Costumes

The code for the Costume form (cont.)
  • private void LoadCostumeDropDownList()
  • DictionaryEntry Costume
  • foreach (Costume c in Costumes)
  • ddlCostumes.Items.Add(c.Key)
  • private void ddlCostumes_SelectedIndexChanged
    (Object sender, System.EventArgs e)
  • lblPrice.Text CostumesddlCostumes.SelectedI
  • private btnOrder_Click(Object sender,
    System.EventArgs e)
  • Order order new Order(ddlCostumes.SelectedIt
  • txtQuantity.Text, lblPrice.Text)
  • Session("Order") order
  • OrdersDB.Write(order)
  • Response.Redirect("Confirmation.aspx")

The code for the Confirmation form
  • public class Confirmation System.Web.UI.Page
  • private void Page_Load(Object sender,
    System.EventArgs e)
  • Order order Session"Order
  • lblConfirm.Text "Thank you for your order of
  • order.Quantity " "
  • " costume" ((order.Quantity gt 1 ?
    "s" "")
  • " _at_ " order.UnitPrice
  • "It will be shipped on "
  • Now().Date.AddDays(1) ".
  • private void btnReturn_Click(Object sender,
    System.EventArgs e)
  • Response.Redirect("Costume.aspx")

The code for the Web forms
  • The code for a form is stored in a file called a
    code-behind file. This code includes event
    procedures that are called by ASP.NET when the
    user interacts with the controls on the page.
  • Each time a page is executed, ASP.NET executes
    the procedure for the Load event of the form.
    Within this event procedure, you can test the
    IsPostBack property of the page to determine if
    the page is being loaded for the first time or if
    its being posted back to the server.
  • You can use the Session property of the page to
    save items in and retrieve items from the session
    state object.

The code for the web forms (cont.)
  • You can use the Redirect method of the
    HttpResponse object associated with the page to
    display a form other than the one thats
    currently displayed. To refer to this object, you
    use the Response property of the page.
  • A web form inherits the System.Web.UI.Page class
    defined by the .NET Framework. This class defines
    the basic functionality for all web pages.
  • Note
  • Since the page is the default object within a
    code-behind file, you dont need to refer to it
    explicitly to use its properties and methods.

Order and OrdersDB classes
  • public class Order
  • public String Name
  • public String Product
  • public String Quantity
  • public int UnitPrice
  • using System.IO
  • public class OrdersDB
  • public static string OrderFile
  • public static string CostumeFile
  • public static NameValueCollection
  • NameValueCollection costumes new
  • FileStream costumeStream new
  • FileMode.Open, FileAccess.Read)
  • BinaryReader costumeReader new
  • while (costumeReader.PeekChar())
  • string sName costumeReader.ReadString()

  • public static void Write(Order order)
  • FileStream orderStream new FileStream(ordersFi
    le, FileMode.Append, FileAccess.Write)
  • StreamWriter OrderWriter new
  • OrderWriter.WriteLine(order.Name ","
  • order.Product ","
  • order.Quantity "," order.UnitPrice)
  • OrderWriter.Close()

HTML file
To web server
HTML code
C compiler
To web server
C code-behind files
Other classes
How an ASP.NET application is compiled
HTML code
Page class
Compiled page
How the files of an ASP.NET application are
stored and compiled
  • When you build an ASP.NET application, the VB.NET
    compiler compiles the files that contain C code
    to create an assembly. The assembly is stored in
    a DLL file on the web server.
  • The aspx files that contain the HTML code are not
    compiled along with the C code. Instead, those
    files are stored in their original format on the
    web server.
  • When the user requests an ASP.NET page, ASP.NET
  • creates a class file from the aspx file for the
  • compiles that class file and the code it inherits
    from the C assembly into a single assembly
    thats stored on disk in a DLL file
  • executes the DLL to generate the page

Components of an ASP.NET application
HTTP request
HTTP response
Web server (IIS)
ASP.NET (aspnet_isapi.dll)
Generated HTML page
Compiled Page (dll)
Instantiated page class
How ASP.NET applications work
  • When IIS receives an HTTP request for an ASP.NET
    page, it forwards the request to ASP.NET. ASP.NET
    then creates and executes a compiled page that
    combines the page class with the compiled C
  • When the compiled page is executed, an instance
    of the ASP.NET page class is generated. Then,
    ASP.NET raises the appropriate events, which are
    processed by the event handlers in the page.
    Finally, the page generates the HTML thats
    passed back to IIS.
  • The ASP.NET page is compiled only the first time
    its requested. After that, the page is run
    directly from the DLL file.

Elements of an ASP.NET application
Presentation layer
HTML pages
User controls
Style sheets
Business Rules layer
Code behind
Code behind
for user
Other classes
for .aspx files
Database layer
Elements of an ASP.NET applications
  • Presentation layer
  • HTML pages (.aspx files) that define the layout
    of each web page
  • user controls (.ascx files) that define page
    elements such as banners, navigation menus, and
    data entry forms
  • style sheets (.css files) that control the
    overall appearance of the pages.
  • Business Rules layer
  • class files that provide the code-behind
    functions for each page (.aspx.cs)
  • user control (.ascx.cs) to implement the
    applications processing requirements
  • other classes (.cs), such as classes that
    represent business entities or implement business
  • Database layer
  • the database itself (such as Microsoft SQL
    Server) as well as classes that work directly
    with the database.