asp.net session 19

Upload: prerana-tokas

Post on 14-Apr-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/30/2019 ASP.net Session 19

    1/35

    Slide 1 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    In this session, you will learn to:

    Configure a Web server for deployment

    Deploy a Web application

    Implement tracing in Web applications

    Objectives

  • 7/30/2019 ASP.net Session 19

    2/35

    Slide 2 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    Web servers accept requests from Web browsers and

    respond accordingly.

    To enable a Web server to respond to a browser, you need

    to configure it.

    The configuration of a Web server involves performing thefollowing tasks:

    Creating a virtual directory

    Defining Web application URLs

    Registering ASP.NET file mappings

    Configuring a Web Server for Deployment

  • 7/30/2019 ASP.net Session 19

    3/35

    Slide 3 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    A virtual directory is created so that the user does not get

    direct access to the Web application folder residing on the

    host computer.

    A virtual directory exposes the components of a Web

    application to the remote clients and allows them to accessyour Web application through Web browsers.

    The Virtual Directory

    Let us see how to deploy a website by creating a virtual

    directory

  • 7/30/2019 ASP.net Session 19

    4/35

    Slide 4 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    After creating the virtual directory, you can configure the

    application pool for your application.

    An Application pool can contain one or more applications

    and allows you to configure the level of isolation between

    different Web applications.You can configure application pools for your Web

    applications by using the IIS manager.

    For this, you need to right-click the virtual directory that is

    created for the Web application and select the Properties

    option.You can set the isolation for your application by selecting

    the appropriate option from the Application Protection

    drop-down list.

    The Virtual Directory (Contd.)

  • 7/30/2019 ASP.net Session 19

    5/35

    Slide 5 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    The Properties dialog box provides the following application

    protection options:

    Low (IIS Process)

    Medium (Pooled)

    High (Isolated)

    The Virtual Directory (Contd.)

  • 7/30/2019 ASP.net Session 19

    6/35

    Slide 6 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    Users access a Web application by using an

    easy-to-remember address in the address bar of a Web

    browser known as the Uniform Resource Locator (URL).

    A URL is the location of a file on the Web and is unique for

    every application.To access a Web application, users type the URL for that

    application in the address bar of a Web browser.

    The Web browser sends this request to the Web server.

    The Web server then searches for the application mapped

    to that URL and sends it back to the browser.

    Web Application URLs

  • 7/30/2019 ASP.net Session 19

    7/35Slide 7 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    When multiple versions of .NET Framework are installed on

    the same computer, each version installs an ASP.NET

    Internet Server Application Programming Interface (ISAPI)

    extension version associated with it.

    The ISAPI extension version determines which version ofthe Common Language Runtime (CLR) will be used by a

    particular Web application.

    To configure a Web application to use a particular version,

    you need to register a script map in the Internet Information

    Services (IIS).

    Registering ASP.NET File Mappings

  • 7/30/2019 ASP.net Session 19

    8/35Slide 8 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    A script map is a path to the ASP.NET ISAPI version used

    by the application.

    When a user requests for a particular Web page, the script

    map for the application directs IIS to forward the requested

    file to the appropriate version of the ASP.NET ISAPI forprocessing.

    To use a particular version of the .NET Framework, you

    need to update the script maps so that the request for a

    Web page is forwarded to the appropriate version of the

    ASP.NET ISAPI for processing.

    To update the script map, you need to use the ASP.NET

    registration tool called aspnet_regiis.exe.

    Registering ASP.NET File Mappings (Contd.)

  • 7/30/2019 ASP.net Session 19

    9/35Slide 9 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    The process of installing a Web application on a Web server

    is known as deployment.

    The most basic technique for deployment is to copy the

    application components to the hard drive of the Web server.

    This type of deployment has the following issues:The application is deployed even if it contains compilationerrors.

    The source code of the application is exposed.

    The application loads slowly initially because it is compiled

    when it is accessed for the first time.

    These problems can be resolved by precompiling an

    application before deploying it to a Web server.

    Deploying a Web Application

  • 7/30/2019 ASP.net Session 19

    10/35Slide 10 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    Precompilation involves compilation of the source code of

    the Web application into DLL assemblies before

    deployment.

    Advantages of precompiling a Web application are:

    Provides faster response timeHelps in identifying the bugs that can occur when a Web page

    is requested

    Hides and secures the source code of a Web application from

    users accessing the application

    You can precompile a Web application by using the

    aspnet_compiler.exe command-line tool.

    Precompiling a Web Application

  • 7/30/2019 ASP.net Session 19

    11/35Slide 11 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    To compile a website, you need to execute the

    aspnet_complier command, as shown in the following

    figure.

    Precompiling a Web Application (Contd.)

  • 7/30/2019 ASP.net Session 19

    12/35Slide 12 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    The following table lists some options that can be used with

    aspnet_compiler.exe tool.

    Precompiling a Web Application (Contd.)

    Opt ion Descr ipt ion

    -v Specifies the virtual path of the application to be compiled.

    -p Specifies the physical path of the application to becompiled.

    -u Specifies that aspnet_compiler.exe should create a

    precompiled application that allows subsequent updates of

    contents such as .aspx pages.

    -c Specifies that the application to be compiled should be fully

    rebuilt.

  • 7/30/2019 ASP.net Session 19

    13/35Slide 13 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    The compilation tool of ASP.NET, aspnet_compiler.exe,

    compiles the source files and creates separate assemblies

    for each source file.

    The assemblies are then combined and managed by using

    the ASP.NET merge tool, aspnet_merge.exe.

    The ASP.NET merge tool can be used to combine:

    All assemblies in a precompiled website into a single

    assembly.

    All Web user interface content assemblies into a single

    assembly.

    All Web user interface content assemblies into an assembly

    for each folder in the website.

    Managing ASP.NET Precompiled Output for Deployment

  • 7/30/2019 ASP.net Session 19

    14/35Slide 14 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    When you use the aspnet_merge tool, without any options,

    and only specify the target folder name, as shown in the

    following figure, output assemblies are created for each

    Web user interface content folder.

    Managing ASP.NET Precompiled Output for Deployment (Contd.)

  • 7/30/2019 ASP.net Session 19

    15/35Slide 15 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    To create a single assembly that combines all Web user

    interface content assemblies, you need to use the w switch

    with the aspnet_merge tool and specify a name for the

    merged assembly, as shown in the following figure.

    Managing ASP.NET Precompiled Output for Deployment (Contd.)

  • 7/30/2019 ASP.net Session 19

    16/35Slide 16 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    To create a single assembly that combines all assemblies in

    a precompiled website, you need to use the o switch with

    the aspnet_merge tool and specify a name for the merged

    assembly, as shown in the following figure.

    Managing ASP.NET Precompiled Output for Deployment (Contd.)

  • 7/30/2019 ASP.net Session 19

    17/35Slide 17 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    Managing ASP.NET Precompiled Output for Deployment (Contd.)

    Let us see how to deploy a website by using the Copy Web Site

    utility

    Let us see how to deploy a website by using the Publish Web Site

    utility

    Let us see how to deploy a setup project by using a Web Setup

    project

    Microsoft Visual Studio provides the following methods to

    deploy a Web application:

    Copy Web Site utility

    Publish Web Site utility

    Web Setup project

  • 7/30/2019 ASP.net Session 19

    18/35Slide 18 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    Debugging a Deployed Application

    Let us see how to debug a deployed application

    You can debug an application even after it has been

    deployed to a Web server.

  • 7/30/2019 ASP.net Session 19

    19/35Slide 19 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    To ensure that the application is working properly and is not

    giving unexpected results, you need to keep track of the

    execution of your Web application.

    ASP.NET provides you with the tracing feature that enables

    you to track the program execution, thereby ensuring that

    your Web application runs properly.

    You can use tracing feature to:

    View diagnostic information about a particular Web page.

    Display custom tracing information about the execution of an

    application.

    Implementing Tracing in Web Applications

  • 7/30/2019 ASP.net Session 19

    20/35Slide 20 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    Tracing can be implemented at any of the following levels:

    Page level

    Application level

    Implementing Tracing

  • 7/30/2019 ASP.net Session 19

    21/35Slide 21 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    Page-level tracing:

    Page-level tracing is used to generate diagnostic information at

    the end of page rendering.

    The diagnostic information includes all the information about

    the requests made to the page and their responses.

    To enable page-level tracing, you need to perform the following

    steps:

    1. Include the following directive at the top of the page:

    2. Include the TraceMode attribute in the @ Page directive to

    specify the sort order for your trace messages.

    Implementing Tracing (Contd.)

  • 7/30/2019 ASP.net Session 19

    22/35Slide 22 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    The following information is displayed when page-level tracing

    is enabled:

    Request details

    Trace information

    Control tree

    Session stateApplication state

    Request Cookies Collection

    Response Cookies Collection

    Headers Collection

    Response Headers Collection

    Form Collection

    Querystring Collection

    Server Variables

    Implementing Tracing (Contd.)

  • 7/30/2019 ASP.net Session 19

    23/35

    Slide 23 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    Application-level tracing:

    Application-level tracing is used to trace information for every

    Web page in a Web application.

    A special page named trace.axd is used to view this trace

    information.

    To use the trace.axd page, you have to first enable

    application-level tracing within the Web.config file for your

    application.

    You can use the following attributes of the element to

    change the tracing settings of your website:

    enabledrequestLimit

    pageOutput

    traceMode

    localOnly

    mostRecent

    Implementing Tracing (Contd.)

  • 7/30/2019 ASP.net Session 19

    24/35

    Slide 24 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    When a Web application is in the development stage, youoften use several Response.Write statements in the

    program code to display debugging information, which is

    used to troubleshoot the application.

    The messages displayed using Response.Write

    statements are required for debugging and should not be

    displayed to an end user.

    The process of tracing enables you to insert debugging

    code within an application such that the debugging code

    does not need to be removed at the time of deployment.

    The Trace property of the Page class returns a Trace

    object, which can be used to write custom trace statements.

    Writing Trace Information

  • 7/30/2019 ASP.net Session 19

    25/35

    Slide 25 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    The Trace object:

    Is an instance of the TraceContext class.

    Provides a set of methods and properties that help you to trace

    the execution of your application.

    The properties of the Trace object are:

    IsEnabled: Denotes whether tracing is enabled for the

    current request.

    TraceMode: Sets the trace modes such as sortByCategory

    orsortByTime.

    Some of the methods of the Trace object are:

    Warn: Displays the trace information in red color.

    Write: Displays the trace information in black color.

    Writing Trace Information (Contd.)

  • 7/30/2019 ASP.net Session 19

    26/35

    Slide 26 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    Trace listeners are used to:

    Collect, store, and route tracing messages.

    Redirect the tracing information to logs, windows, or text files.

    ASP.NET provides three types of predefined trace listeners:

    TextWriterTraceListenerEventLogTraceListener

    DefaultTraceListener

    Using Trace Listeners

  • 7/30/2019 ASP.net Session 19

    27/35

    Slide 27 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    Adding a trace listener:

    To add a trace listener in the web.config file, you need to

    include the following markup in the web.config file:

    Using Trace Listeners (Contd.)

  • 7/30/2019 ASP.net Session 19

    28/35

    Slide 28 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    To enable ASP.NET to route tracing information to aSystem.Diagnostics listener, you need to include the

    following entry in the web.config file:

    Using Trace Listeners (Contd.)

  • 7/30/2019 ASP.net Session 19

    29/35

    Slide 29 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    Removing a trace listener:

    To remove a trace listener from the listeners collection, you

    need to include the following markup in the web.config file:

    Using Trace Listeners (Contd.)

  • 7/30/2019 ASP.net Session 19

    30/35

    Slide 30 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    You can control the tracing output by using trace switches.

    Trace switches can be configured to provide filtered tracing

    output.

    You can also enable and disable certain tracing output using

    trace switches.The two types of trace switches are:

    BooleanSwitch

    TraceSwitch

    To initialize a TraceSwitch, you need to first create its object.

    The following code snippet shows how you can create andinitialize a TraceSwitch:

    System.Diagnostics.TraceSwitch MyTraceSwitch = new

    System.Diagnostics.TraceSwitch("MySwitch", "Entire

    application");

    Trace Switches

  • 7/30/2019 ASP.net Session 19

    31/35

    Slide 31 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    Problem Statement:

    Your team leader wants you to implement tracing on the

    MusicMania website. You are instructed to display the trace

    data for all the Web pages on the MusicMania website. The

    trace data should not be displayed on individual Web pages. It

    should be displayed on the host Web server for a maximum of50 recent requests. You also need to save the trace data in a

    text file.

    Activity 14.1: Implementing Tracing

  • 7/30/2019 ASP.net Session 19

    32/35

    Slide 32 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    Solution:

    To implement tracing in the MusicMania website, you need to

    perform the following tasks:

    1. Modify the web.config file.

    2. Verify the application.

    Activity 14.1: Implementing Tracing (Contd.)

  • 7/30/2019 ASP.net Session 19

    33/35

    Slide 33 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    In this session, you learned that:

    The configuration of a Web server involves performing the

    following tasks:

    Creating a virtual directory

    Defining Web application URLs

    Registering ASP.NET file mappings

    A virtual directory is created so that the user does not get direct

    access to the Web application folder residing on the host

    computer.

    A virtual directory exposes the components of a Web

    application to the remote clients and allows them to accessyour Web application through Web browsers.

    An Application pool can contain one or more applications and

    allows you to configure the level of isolation between different

    Web applications.

    Summary

  • 7/30/2019 ASP.net Session 19

    34/35

    Slide 34 of 35Ver. 1.0

    Developing Web Applications Using ASP.NET

    A URL is the location of a file on the Web. It is unique for every

    application.

    Precompilation involves compilation of the source code of the

    Web application into DLL assemblies before deployment.

    Precompiling a Web application provides the following

    advantages:It provides faster response time because the Web application

    does not need to be compiled the first time it is accessed.

    It helps in identifying the bugs that can occur when a Web page is

    requested. These bugs are rectified at the time of compiling the

    Web application. Then the compiled and error-free Web

    application is deployed on to the server and is rendered to a user.It hides and secures the source code of a Web application from

    users accessing the application.

    The compilation tool of ASP.NET, aspnet_compiler.exe,

    compiles the source files and creates separate assemblies for

    each source file.

    Summary (Contd.)

    l i b li i i S

  • 7/30/2019 ASP.net Session 19

    35/35

    Developing Web Applications Using ASP.NET

    Tracing can be implemented at any of the following levels:

    Page level

    Application Level

    The properties of the Trace object are:

    IsEnabled

    TraceMode

    Some of the methods of the Trace object are:

    Warn

    Write

    ASP.NET provides three types of predefined trace listeners:

    TextWriterTraceListenerEventLogTraceListener

    DefaultTraceListener

    Summary (Contd.)