Configuring, Deploying, Tracing and Error Handling

Post on 21-Jan-2016

47 views 0 download

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

Transcript of Configuring, Deploying, Tracing and Error Handling

IT533 Lectures

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

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

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

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

our IIS server.Look at Properties of the application:

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

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 -->

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

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>

ConfigurationConfiguration Hierarchy

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

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

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

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

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

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

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

TracingTracing Demo

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

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

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>

Error HandlingCustom Error Pages

Can configure error pages on IIS Properties

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