20
IT533 Lectures Configuring, Deploying, Tracing and Error Handling

Configuring, Deploying, Tracing and Error Handling

  • Upload
    hilde

  • View
    67

  • Download
    0

Embed Size (px)

DESCRIPTION

Configuring, Deploying, Tracing and Error Handling. IT533 Lectures. IIS. Internet Information Server Microsoft’s web server http://www.iis.net/ Foundation for ASP.NET Runs in inetinfo.exe process Also FTP, NNTP, SMTP Shared resources Default location c:\inetpub\wwwroot - PowerPoint PPT Presentation

Citation preview

Page 1: Configuring, Deploying,  Tracing  and Error Handling

IT533 Lectures

Configuring, Deploying, Tracing and Error Handling

Page 2: Configuring, Deploying,  Tracing  and Error Handling

IISInternet Information Server

Microsoft’s web serverhttp://www.iis.net/Foundation for ASP.NETRuns in inetinfo.exe process

Also FTP, NNTP, SMTPShared resources

Default location c:\inetpub\wwwrootInternet Services Manager

A Microsoft Management Console (MMC) snap-in

Page 3: Configuring, Deploying,  Tracing  and Error Handling

IISVirtual Directories

Provides a level of indirection from URL to actual file locations on the server

For example, the file for the url: http://myServer/myApplication/foo.asp

could be mapped to the physical location:d:\myFolder\myAppFolder\foo.asp

Page 4: Configuring, Deploying,  Tracing  and Error Handling

DeploymentXCOPY deployment

Components are placed in .\bin folderNo DLL deployment, registration

Unless you’re using COM or other DLLsNo locked DLLs

DLLs are “shadow copied” into a hidden folder.aspx files are automatically compiled

Not true for codebehindUpdate code (.aspx and assemblies) while server

is runningNo need to stop/bounce the server

Page 5: Configuring, Deploying,  Tracing  and Error Handling

DemoLet’s take a website we’ve implemented and deloy it to

our IIS server.Look at Properties of the application:

Page 6: Configuring, Deploying,  Tracing  and Error Handling

ConfigurationGoal

Provide extensible configuration for admins & developers to hierarchically apply settings for an application

SolutionStore configuration data in XML text files

Format is human- and machine- readable and writable

Page 7: Configuring, Deploying,  Tracing  and Error Handling

ConfigurationSettings specified in configuration sections, e.g.

Security, SessionState, Compilation, CustomErrors, ProcessModel, HTTPHandlers, Globalization, AppSettings, WebServices, WebControls, etc.

Configuration information stored in web.configIt is just a file, no DLL registration, no Registry settings,

no Metabase settings<!– web.config can have comments -->

Page 8: Configuring, Deploying,  Tracing  and Error Handling

ConfigurationConfiguration Hierarchy

Configuration files can be stored in application foldersConfiguration system automatically detects changes

Hierarchical configuration architectureApplies to the actual directory and all subdirectories

RootDir

SubDir1

SubDir2

web.config

Page 9: Configuring, Deploying,  Tracing  and Error Handling

Configurationweb.config Sample

web.config sample<configuration> <configsections> <add names=“httpmodules“ type=“System.Web.Config.HttpModulesConfigHandler“/> <add names=“sessionstate“ type=“...“/> </configsections>

<httpmodules> <!--- http module subelements go here --> </httpmodules>

<sessionstate> <!--- sessionstate subelements go here --> </sessionstate></configuration>

Page 10: Configuring, Deploying,  Tracing  and Error Handling

ConfigurationConfiguration Hierarchy

Standard machine-wide configuration fileProvides standard set of configuration section handlers

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config

Page 11: Configuring, Deploying,  Tracing  and Error Handling

ConfigurationUser-defined Settings

In root web.config

<appSettings> <add key="customsetting1" value="Some text here"/> </appSettings>

string customSetting = System.Configuration.ConfigurationManager.AppSettings.Get("customsetting1");

Retrieve settings at run-time

Page 12: Configuring, Deploying,  Tracing  and Error Handling

Tracing

ASP.NET supports tracing Easy way to include “debug” statements No more messy Response.Write() calls!Debug statements can be left in, but turned off

Great way to collect request detailsServer control treeServer variables, headers, cookiesForm/Query string parametersTracing provides a wealth of information about the page

Can be enabled at page- or application- levelhttp://msdn.microsoft.com/en-us/library/0x5wc973.aspx

Page 13: Configuring, Deploying,  Tracing  and Error Handling

TracingMethods and Properties

MethodsTrace.Write: Writes category and text to traceTrace.Warn: Writes category and text to trace in red

PropertiesTrace.IsEnabled: True if tracing is turned on for

the application or just that pageTrace.Mode: SortByTime, SortByCategory

Implemented in System.Web.TraceContext class

Page 14: Configuring, Deploying,  Tracing  and Error Handling

TracingApplication-Level Tracing

To enable tracing across multiple pages:1. Write web.config file in application root

2. Hit one or more pages in the application3. Access tracing URL for the application

<configuration> <system.web> <trace enabled="true" pageOutput="false"

requestLimit="40" localOnly="false"/> </system.web> </configuration>

http://localhost:port/WebsiteName/Trace.axd

Page 15: Configuring, Deploying,  Tracing  and Error Handling

TracingPage-Level Tracing

To enable tracing for a single page:1. Add trace directive at top of page

<%@ Page Trace=“True” %>

2. Add trace calls throughout page Trace.Write(“MyApp”, “Button Clicked”); Trace.Write(“MyApp”, “Value: ” + value);

3. Access page from browser

Page 16: Configuring, Deploying,  Tracing  and Error Handling

TracingTracing Demo

Let’s add some traces to the AjaxExample websiteShow information obtained from tracing

Page 17: Configuring, Deploying,  Tracing  and Error Handling

Error Handling.NET Common Language Runtime provides a unified

exception architectureRuntime errors done using exceptionsVB now supports try/catch/finally

ASP.NET also provides declarative application custom error handlingAutomatically redirect users to error page when unhandled

exceptions occurPrevents ugly error messages from being sent to users

Page 18: Configuring, Deploying,  Tracing  and Error Handling

Error HandlingCustom Error Pages

Can specify error pages for specific HTTP status codes in web.config

<configuration> <customerrors mode=“remoteonly” defaultredirect=“error.htm”> <error statuscode=“404” redirect=“adminmessage.htm”/> <error statuscode=“403” redirect=“noaccessallowed.htm”/> </customerrors> </configuration>

Page 19: Configuring, Deploying,  Tracing  and Error Handling

Error HandlingCustom Error Pages

Can configure error pages on IIS Properties

Page 20: Configuring, Deploying,  Tracing  and Error Handling

Error HandlingError Event

What do you actually do when an error occurs?Add global.asax to your websiteUse System.Diagnostics.EventLog class to

write custom events to log when errors occurUse System.Web.Mail.SmtpMail class to send

email to administrators