+ All Categories
Home > Documents > Tutorial ASP 014

Tutorial ASP 014

Date post: 03-Apr-2018
Category:
Upload: marouane-bouzid
View: 228 times
Download: 0 times
Share this document with a friend

of 74

Transcript
  • 7/29/2019 Tutorial ASP 014

    1/74

    ASP.NET

    Module Subtitle

  • 7/29/2019 Tutorial ASP 014

    2/74

    Objectives

    Introduction to ASP.NET

    Concepts and Architecture

    ASP.NET Features

    Advanced ASP.NET

    ASP.NET and the Microsoft .NET Framework

  • 7/29/2019 Tutorial ASP 014

    3/74

    Contents

    Section 1: Overview

    Section 2: Architecture

    Microsoft .NET Framework and ASP.NET Configuration

    Section 3: ASP.NET Features State Management, Security, and Event Model

    Section 4: Advanced ASP.NET

    Web Forms and Web Services

    Working with Data

    ASP to ASP.NET Migration

    Appendix: Exploring Duwamish Online

  • 7/29/2019 Tutorial ASP 014

    4/74

    Section 1: Overview

    Looking Back ...

    ASP.NET Core Concepts

  • 7/29/2019 Tutorial ASP 014

    5/74

    Looking Back: Active Server Pages

    What is ASP? Server-side scripting technology

    Files containing HTML and scripting code

    Access via HTTP requests

    Scripting code is interpreted on server side

    What can I do with ASP?

    Easily and quickly create simple Web applications

    Generate dynamic Web content Client-side scripting for validation

    Access COM components to extend functionality

    Databases

  • 7/29/2019 Tutorial ASP 014

    6/74

    Whats Wrong with That?

    Mixes layout (HTML) and logic (scripting code)

    Interpreting ASP code leads to performance loss

    Uses scripting languages that are not strongly typed

    Microsoft JScript

    Microsoft Visual Basic Scripting Edition (VBScript)

    Browser compatibility

    No real state management No state sharing across Web farms

    State is lost when IIS fails

    Update files only when server is down

  • 7/29/2019 Tutorial ASP 014

    7/74

    ASP.NET Core Concepts

    Web development platform

    New programming model

    Web Client

    Operating System

    ASP.NET

    ApplicationsIIS

    .NETFramework

  • 7/29/2019 Tutorial ASP 014

    8/74

    ASP.NET Core Concepts

    Separate layout and business logic

    Use services provided by the .NET Framework

    Code is compiled the first time a page is requested

    State management

    Make use of programming languages

    Cross-language integration

    Update files while the server is running!

  • 7/29/2019 Tutorial ASP 014

    9/74

    Section 2: Architecture

    The .NET Framework Architecture

    Web Application Model

    Configuration

    Class Hierarchy

  • 7/29/2019 Tutorial ASP 014

    10/74

    The .NET Framework Architecture

    Microsoft .NET Framework

    System Services

    Common Language Runtime

    ASP.NET

    Web Forms Web ServicesWindows Forms

    Services Framework

    Base Data Debug ...

  • 7/29/2019 Tutorial ASP 014

    11/74

    Web Application Model

    Unmanaged Code

    Managed Code

    ...Request Handler

    HTTP Module

    HTTP Module

    HTTP Runtime

    Host (IIS, Internet Explorer)

    HTTP Request

  • 7/29/2019 Tutorial ASP 014

    12/74

    HTTP Runtime

    Managed code Runs within an unmanaged host process

    Aims for 100% availability

    Asynchronously processes all requests

    Multithreaded

    Replaces ISAPI

    Internet Server Application Programming Interface

  • 7/29/2019 Tutorial ASP 014

    13/74

    HTTP Module Pipeline

    HTTP module pipeline Managed classes

    Each module implements a specific interface

    For example: state management or security

    All requests are routed through the same pipeline

    Add modules through Web.Config

    Request handler

    Managed classes Multiple request handlers for one application

    But only one per URL

  • 7/29/2019 Tutorial ASP 014

    14/74

    Hierarchical Configuration

    Configuration file: Web.Config

    XML-based, human readable and writeable

    File is kept within the application directory

    Changes are automatically detected

    Influence on the actual dir and all subs But:

    Lock settings with attribute: allowOverride=false

    RootDir

    Sub

    Dir1Sub

    Dir2

    Web.Config

  • 7/29/2019 Tutorial ASP 014

    15/74

    Web.Config sample

  • 7/29/2019 Tutorial ASP 014

    16/74

    Custom Configuration

    Default machine.config (!) file is placed in %windir%\Microsoft.NET\Framework\\CONFIG

    Standard set of configuration section handlers

    Browser capabilities, custom error messages, and so on

    Customized configuration

    Extend the set of section handlers with your own

    Implement the interface:

    System.Configuration.IConfigurationSectionHandler

    Problems with

    Virtual directories and non-ASP.NET files

  • 7/29/2019 Tutorial ASP 014

    17/74

    Class Hierarchy 1/2

    Namespaces Hierarchically structured

    Dot-syntax, grouping classes logically

    Abstract base classes and class implementations

    You are free to implement your own

    Sample: System.Web.UI.WebControls.Buttonnamespace class name

    How to use namespaces: using MyAlias = System.Web.UI.WebControls

  • 7/29/2019 Tutorial ASP 014

    18/74

    Class Hierarchy 2/2

    System.Web.UI.

    WebControlsListControl

    ListBox

    CheckBoxList

    Button

    Table

    WebControl

    System.Web.UI.Control

    System.Object

    TextBox

    ......

  • 7/29/2019 Tutorial ASP 014

    19/74

    Section 3: Features

    ASP.NET Syntax and Supported Languages Samples

    Execution Process

    Assemblies

    State Management, Security, and Event Handling

  • 7/29/2019 Tutorial ASP 014

    20/74

    Business Logic and Layout

    No more blending of HTML and scripting code Easy maintainability of your application

    Completely separate layout and processing logic

    No implementation code within HTML files Files for designers and files for programmers

    You can still mix HTML and scripting code if you wish

    .aspx.aspx.cs

    .cs

  • 7/29/2019 Tutorial ASP 014

    21/74

    Supported Languages

    Visual Basic VBScript is unmanaged !

    JScript

    C# New component-based language

    C++

    Managed Extensions for C++

    Others: Cobol, Smalltalk, ...

    Common Language Specification (CLS)

  • 7/29/2019 Tutorial ASP 014

    22/74

    C# Overview

    New component-oriented language from Microsoft

    Evolution of C and C++

    Introduces improvement in areas such as

    Type safety, versioning, events and garbage collection

    Provides access to APIs like .NET, COM, or Automation Hello World sample

    using System;namespace hwsample{public class Hello {public static void Main() {Console.WriteLine(Hello World!);}}}

  • 7/29/2019 Tutorial ASP 014

    23/74

    QuickStart

    Different files with different file name extensions Standard ASP.NET files: .aspxor.ascx

    Web Services: .asmx

    Code (behind) files: .aspx.cs, .asmx.vb, ...

    Configuration: Web.Config

    Web applications: Global.asax and Global.asax.vb

    All of them are text files

    The easiest way to start

    Change the .asp extension to .aspx

  • 7/29/2019 Tutorial ASP 014

    24/74

    Page Syntax1/3

    Directives

    Code Declaration Blocks

    [ lines of code ]

    Code Render Blocks

    HTML Control Syntax

  • 7/29/2019 Tutorial ASP 014

    25/74

    Page Syntax2/3

    Custom Control Syntax Custom server controls

    Server control property

    Subproperty

    Server control event binding

  • 7/29/2019 Tutorial ASP 014

    26/74

    Page Syntax3/3

    Data Binding Expression

    Server-side Object Tags

    Server-side Include Directives

    Server-side Comments

  • 7/29/2019 Tutorial ASP 014

    27/74

    ASP.NET Sample1/2Sub SubmitBtn_Click(Sender As Object, E As EventArgs)Message.Text = Hi & Name.TextEnd Sub Name:

  • 7/29/2019 Tutorial ASP 014

    28/74

    ASP.NET Sample2/2

  • 7/29/2019 Tutorial ASP 014

    29/74

    Code

    behind

    .aspx Execution Cycle

    IIS

    ASP.NET Runtime

    Instantiate controls

    Parse .aspx file

    Generate page class

    Request .aspx file

    Response

    Client Server

  • 7/29/2019 Tutorial ASP 014

    30/74

    Execution process

    Compilation, when page is requested the first time

    Microsoft intermediate language (MSIL)

    Assembly languagelike style

    CPU independent

    Provides a hardware abstraction layer

    MSIL is executed by the common language runtime

    Common language runtime

    Just-in-time (JIT) compiler

    Managed code

  • 7/29/2019 Tutorial ASP 014

    31/74

    Assemblies

    Result of compiling is still a .dll or .exe file Multiple- or single-file assembly

    Assembly 1

    MyApp.dll

    pic1.jpg

    metadata

    Assembly 2

    MyApp.dll

    metadatasharedname

  • 7/29/2019 Tutorial ASP 014

    32/74

    Metadata

    An assemblys manifestA manifest contains

    List of all assembly files

    Information about versioning, shared name

    and more ...

    The information is used to

    Locate and load class types

    Lay out object instances in memory

    Resolve method invocations and field references

    Translate MSIL to native code

    Enforce security

  • 7/29/2019 Tutorial ASP 014

    33/74

    State Management1/2

    Application State What is an application?

    Files, pages, modules, and executable code

    One virtual directory and its subdirectories

    Application state variables Global information

    Implementation rules

    Use of system resources

    Lock and unlock your global information

    Beware of global variables in multithreaded environments

    Loss of state when host is destroyed

    No state sharing across Web farms

  • 7/29/2019 Tutorial ASP 014

    34/74

    State Management2/2

    Session State What is a session?

    Restricted to a logical application

    Context in which a user communicates with a server

    Functionality

    Request identification and classification

    Store data across multiple requests

    Session events

    Release of session data

    .NET State Server Process

  • 7/29/2019 Tutorial ASP 014

    35/74

    Security 1/3

    Reasons for Security Prevent access to areas of your Web server

    Record and store secure relevant user data

    Security Configuration in Web.Config

    , , , ...

    Authentication, Authorization, Impersonation

    Code Access Security

    Are you the code you told me you are?

    Protect your server from bad code

  • 7/29/2019 Tutorial ASP 014

    36/74

    Security 2/3

    Authentication Validates user credentials

    Awards an authenticated identity

    Types of authentication

    Windows, integrating with IIS 5.0

    Passport, centralized services provided by Microsoft

    Forms, request attachment

    Authorization

    Determine whether request is permitted

    File and URL authorization

  • 7/29/2019 Tutorial ASP 014

    37/74

    Security 3/3

    Impersonation IIS authenticates the user

    A token is passed to the ASP.NET application

    ASP.NET impersonates the given token

    Access is permitted according to NTFS settings

    Code Access Security

    .NET Framework feature

    Verify the codes identity and where it comes from Specify operations the code is allowed to perform

  • 7/29/2019 Tutorial ASP 014

    38/74

    Event Model 1/2

    Application-level Event Handling Web Forms

    Delegate Model

    Connect event sender and event receiver

    Single and multicast delegates

    Event Delegates Are Multicast

    Event Wiring

    Register event handler with event sender

  • 7/29/2019 Tutorial ASP 014

    39/74

    Event Model 2/2

    Events raised on client, but handled on server

    ServerWeb Client

    parse messageevent

    event handler

    event

    message

    response

    call appropriate

    event handler

  • 7/29/2019 Tutorial ASP 014

    40/74

    Event Samples

    Event samples

    System.Web.UI.WebControlsClass Button, public instance event Click

    System.Web.UIClass Page, public instance event Load

    Events in C#ASP.NET

    C#

    protected void btnNext_Click(Object S,ImageClickEventArgs E){ [ ... do something ... ]}

  • 7/29/2019 Tutorial ASP 014

    41/74

    Section 4: Advanced ASP.NET

    Web Forms and Web Services

    Server Controls

    Working with Data

    Web Applications

    Migrating from ASP to ASP.NET

  • 7/29/2019 Tutorial ASP 014

    42/74

    Web Forms Overview 1/2

    thisfile.aspxSubmitBtn_Click(){ ...

    thisfile.aspx.cs......

  • 7/29/2019 Tutorial ASP 014

    43/74

    Web Forms Overview 2/2

    Create programmable Web pages Use any .NET programming language

    Provides a rich set of server-side controls

    Web Forms event model

    Run on any browser

    Visual and logic parts of your Web application

    System.Web.UI.WebControls namespace

  • 7/29/2019 Tutorial ASP 014

    44/74

    Sample Web Forms

    private void SubmitBtn_Click(object s, SystemEventArgs e){ Message.Text=Hi & Name.Text} Name:

    thisfile.aspx.cs:

    thisfile.aspx:

  • 7/29/2019 Tutorial ASP 014

    45/74

    Black boxes providing specific functionality

    Exposed over the Internet

    To be consumed by applications independent of

    Operating system

    Programming language Component model

    Web Services

  • 7/29/2019 Tutorial ASP 014

    46/74

    Web Services Overview 1/2

    For the most part, similar to COM programming

    Based on simple, open standards

    XML-based communication

    Communication = MessagingClient and Web Service are loosely coupled

    URLthe key to Web Services

    http://///?var=value

  • 7/29/2019 Tutorial ASP 014

    47/74

    Web Services Overview 2/2

    Web Service Wire Formats HTTP: GET and POST

    SOAP

    Web Services Description Language (WSDL)

    XML-based

    Abstract description of the Web Service

    Transactions

    ASP.NET transactions = COM+ transactions

  • 7/29/2019 Tutorial ASP 014

    48/74

    Sample Web Service

    using System.Web.Services;public class MyClass : System.Web.Services.WebServices{ [ WebMethod ]public int Compute1(int i1, int i2){ return i1 + i2;}

    public int Compute2(int i1, int i2){if (i1 > i2) return i1 - i2;else return i2 - i1;}}

  • 7/29/2019 Tutorial ASP 014

    49/74

    Server Controls Overview

    Web Forms Server Controls

    Server Controls Families

    HTML

    ASP.NET

    Validation

    User

    Mobile

    Data Binding

    Page Class

    Reunion of code and content

    S C

  • 7/29/2019 Tutorial ASP 014

    50/74

    Server Control Families 1/2

    HTML Server Controls Map directly to HTML elements

    HTML attributes

    Samples: HtmlAnchor(), HtmlTable ()ASP.NET Server Controls

    Abstract controls

    No one-to-one mapping to HTML server controls

    Typed object modelAutomatic browser detection

    Rich set of controls

    Sample: TextBox ()

    S C l F ili

  • 7/29/2019 Tutorial ASP 014

    51/74

    Server Control Families 2/2

    Validation Controls

    Check user input

    Different types of validation

    Required entry

    Comparison, range checking, pattern matching

    User defined

    User Controls (Pagelets)

    Partition and reuse UI functionality

    .ascx file name extension Object model support

    Mobile Controls

    S C t l S t

  • 7/29/2019 Tutorial ASP 014

    52/74

    Server Controls: Syntax

    Focusing ASP.NET Syntax controlName

    TextBox, DropDownList, and so on

    attributes Id=controlID runat=server

    S C t l S l

  • 7/29/2019 Tutorial ASP 014

    53/74

    Server Controls Sample

    foreach (Ivalidator val in Page.Validators){ val.Validate();}

    Checkout.aspx:

    Checkout.aspx.cs:

    W ki ith D t

  • 7/29/2019 Tutorial ASP 014

    54/74

    Working with Data1/3

    SQL and XMLAccess and manipulate data

    Managed data access APIs provided by the runtime

    Essential Objects OleDbConnection, OleDbCommand, and DataSet

    Namespaces

    System.Data and System.Data.OleDb

    W ki ith D t

  • 7/29/2019 Tutorial ASP 014

    55/74

    Working with Data2/3

    ADO.NET Overview

    Disconnected data architecture

    Datasets are complete relational views of data

    XML and XML schema

    InternetData Object

    Dataset

    Windows

    Form

    Web Form

    B2B

    XML

    W ki ith D t

  • 7/29/2019 Tutorial ASP 014

    56/74

    Working with Data3/3

    using System.Data;ShoppingCart.CalculateOrderSummary();DataRow row = ShoppingCart.OrderSummary.Rows[0];lblSubTotal.Text = System.String.Format({0:C},row[OrderData.SUB_TOTAL_FIELD]);

    C#:

    ASP.NET:

    C hi

  • 7/29/2019 Tutorial ASP 014

    57/74

    Caching

    Enhance performance of your Web application

    Output Caching

    Store and retrieve pages or objects

    Page caching

    Fragment caching

    Expiration Rules

    Cache APIs

    Customize caching principles

    W b A li ti

  • 7/29/2019 Tutorial ASP 014

    58/74

    Web Applications

    ASP.NET defines a Web application as thesum of all files, pages, handlers, modules, andexecutable code that can be invoked or run in thescope of a given virtual directory on a web applicationserver

    Distributed Applications

    InternetWeb Service

    Web Form

    Presentation Middle Tier Database

    ASP t ASP NET Mi ti

  • 7/29/2019 Tutorial ASP 014

    59/74

    ASP to ASP.NET Migration

    ASP and ASP.NET can coexist on the same server

    Make use of ASP.NET features

    To migrate, ASP files must be modified

    Migration Wizard generates codebehind Add existing item and Rename

    Performance

    Managed vs. unmanaged code

    Early vs. late binding

    Mi ti I

  • 7/29/2019 Tutorial ASP 014

    60/74

    Migration Issues

    Structure Code blocks and directives

    Security

    ASP.NET security was described earlier

    Languages

    C#, Visual Basic.NET

    Data Access

    ADO to ADO.NET

    S

  • 7/29/2019 Tutorial ASP 014

    61/74

    Summary

    Now you have been introduced to ASP.NET Configuration

    Web Forms and Web Services

    Security

    State Management

    Accessing Data

    Web Applications

    Migration

    Q estions?

  • 7/29/2019 Tutorial ASP 014

    62/74

    Questions?

  • 7/29/2019 Tutorial ASP 014

    63/74

    Duwamish Books

    A Sample Application for Microsoft.NET

    Installing the Sample

  • 7/29/2019 Tutorial ASP 014

    64/74

    Installing the Sample 1/2

    Install the "Enterprise Samples" with Visual Studio.NET

    Location of the C# Version

    Visual Studio.NET folder

    Directory .\EnterpriseSamples\DuwamishOnline CS

    Location of the Visual Basic Version Directory .\EnterpriseSamples\DuwamishOnline VB

    Installation Tasks

    Check the prerequisites

    Microsoft Windows 2000 Server; Microsoft SQL Server 2000

    with English Query optional and supported

    Read the Readme.htm

    Run Installer Duwamish.msi (double-click it)

    Installing the Sample

  • 7/29/2019 Tutorial ASP 014

    65/74

    Installing the Sample 2/2

    The installation wizard will guide you

    Defaults should be OK for almost everybody

    Setup will install database, Web site, and code

    After installation is complete: Visual Studio.NET

    Open the Duwamish.sln file with File/Open Solution

    Can build the sample with Build/Build Solution

    .NET Framework SDK Can build from command line with:

    nmake /a -f duwamish.mak CFG= all is eitherDebug orRelease

    Duwamish Architecture Overview

  • 7/29/2019 Tutorial ASP 014

    66/74

    User / Browser

    IIS

    Duwamish Architecture Overview

    DataAccess

    Database

    C

    ommon.Data

    BusinessRules

    BusinessFacade

    SystemFramework

    Web

    ASP.NET

    ADO.NE

    T

    Common Components

  • 7/29/2019 Tutorial ASP 014

    67/74

    Common Components

    Duwamish7.Common

    Contains systems configuration options

    Contains common data definitions (classes)

    Namespace Duwamish.Common.Data

    "Internal" data representation for Book, Category,Customer, OrderData

    Duwamish7.SystemFramework

    Diagnostics utilities

    Pre and post condition checking classes Dynamic configuration

    In short:

    Everything that's pure tech and not business code

    Duwamish7 DataAccess

  • 7/29/2019 Tutorial ASP 014

    68/74

    Duwamish7.DataAccess

    Contains all database-related code

    Uses ADO.NET architecture

    Using SQL Server managed provider

    Shows DataSet, DataSetCommand usage

    Optimized for performance by using stored procs

    Duwamish7 BusinessRules

  • 7/29/2019 Tutorial ASP 014

    69/74

    Duwamish7.BusinessRules

    Implements all business rules Validation of business objects (Customer EMail)

    Updating business objects

    Calculations (Shipping Cost, Taxes)

    All data access performed through DataAccess

    Duwamish7 BusinessFacade

  • 7/29/2019 Tutorial ASP 014

    70/74

    Duwamish7.BusinessFacade

    Implements logical business subsystems CustomerSystem: Profile management

    OrderSystem: Order management

    ProductSystem: Catalog management

    Reads data through DataAccess

    Data validated and updated using BusinessRules

    BusinessFacade encapsulates all business-related

    functionality

    Duwamish7 Web

  • 7/29/2019 Tutorial ASP 014

    71/74

    Duwamish7.Web

    Implements the user interface for Web access

    Uses ASP.NET architecture

    Employs Web Forms model

    Uses code behind forms

    Manages state

    Uses custom Web controls

    All functionality accessed through BusinessFacade

    Shop at Duwamish Online NET

  • 7/29/2019 Tutorial ASP 014

    72/74

    Shop at Duwamish Online.NETDemo: Duwamish in Action

    Exploring Duwamish Web

  • 7/29/2019 Tutorial ASP 014

    73/74

    Exploring Duwamish.Web

    Exploring ASP.NET Features in Duwamish7.Web

    Legal Notices

  • 7/29/2019 Tutorial ASP 014

    74/74

    Legal Notices

    Unpublished work.

    2001 Microsoft Corporation. All rightsreserved.

    Microsoft, JScript, Visual Basic, Visual Studio, and Windowsare either registered trademarks or trademarks of MicrosoftCorporation in the United States and/or other countries.

    The names of actual companies and products mentionedherein may be the trademarks of their respective owners.


Recommended