Вы находитесь на странице: 1из 7

Application Tracing and Error

Handling
Introduction

Four types of Errors :


• Configuration Errors : Problem in the Web.Config or Machine.Config file
• Parse errors: Caused by incorrect syntax
• Compilation Error : raised by the compiler
• RunTime Error : Detected when the page is executing.
Viewing Error Information:
• Two configuration settings affect how error information is displayed.
• Custom error Mode : It enables or disables custom errors. When this is
enabled, errors on a page or hidden, Three possible values are : On, Off,
RemoteOnly
On means – detailed error information is hidden ,Off – error information is
displayed , Remote – if the request from remote machine, errors are hidden
otherwise errors are displayed
• Debug Mode : When this is enabled, additional information for debugging
runtime errors is displayed.
• <configuration>
<system.web> <customErrors mode=“Off”/></system.web></configuration>
• When the custom errors mode Off,detailed error information is always
displayed.
• In the debug mode, additional debugging information is included with the
compiled code when pages are compiled.
• This mode displays more detailed error information when a runtime error
occurs.
• We can enable the mode for a single page or all pages.
• If a single page , we can mention in the directive and for all pages in the
Web.Config file.
Ex : single page , Debug="True“
web Config file : <compilation debug="true" targetFramework="4.0" />
Page and applictaion level Error handling

• Two ways:
1) Using try – catch – Refer C# coding
2) Page _Error
• Unhandled Exceptions can be handled by Page_Error function .
• We can get the error by using Server.GetLastError()
• It can be cleared by using Server.ClearError();
• Application errors can be handled by Web.Config file.
• We can create global error handler in Global.asax file.
• Enable the custom errors in the config file and redirect the users to a
particular page.

• We can write the code in Application_Error function


Tracing
• ASP.NET tracing enables you to view diagnostic information about a single
request for an ASP.NET page.
• ASP.NET tracing enables you to follow a page's execution path, display
diagnostic information at run time, and debug your application.
• ASP.NET tracing can be integrated with system-level tracing to provide
multiple levels of tracing output in distributed and multi-tier applications.
• Tracing appends diagnostic information and custom tracing messages to the
output of the page and sends this information to the requesting browser.
• Optionally, you can view this information from a separate trace viewer
(Trace.axd) that displays trace information for every page in an ASP.NET Web
application.
• Tracing information can help you investigate errors or unwanted results while
ASP.NET processes a page request.
• We can configure individual pages to display trace information. Alternatively,
you can configure the application's Web.config file so that all pages display
trace information unless the page explicitly disables tracing.
• Setting application-level tracing is useful because you do not have to change
individual pages to enable and disable it
• Trace statements are processed and displayed only when tracing is enabled.
• We can control whether tracing is displayed to a page, to the trace viewer, or
both.
• You enable application-level tracing by using the trace element in the
Web.config file.
• When you enable application-level tracing, ASP.NET collects trace information
for each request to the application, up to the maximum number of requests you
specify.
• The default number of requests is 10. By default, when the trace viewer
reaches its request limit, the application stops storing trace requests.
• You can configure tracing to store the oldest tracing data (discarding newer
items) or the most recent trace information (discarding older items).
• By default, application-level tracing can be viewed only on the local Web
server computer. To make application-level trace information visible from
remote computers, you can set the trace element's LocalOnly attribute to false.
<configuration> <system.web> <trace enabled="true" requestLimit="40"
localOnly="false" /> </system.web> </configuration>
Application Tracing
• We can trace the execution of a page using the trace attribute.
Page Trace = “true”>
• When tracing is enabled , trace information is automatically appended to the
bottom of the page.
• The details are :
request Details : Session ID, time of the request etc..
Trace Information : Steps in the page Execution
Control Tree : Displays the hierarchy of controls in a page
Session State
Application State
Cookies Collection
Headers Collection
Form Collection
QueryString collection
Server Varibles
• All sections are not displayed when tracing is enabled.
• IsEnabled method is used to detect whether the tracing is enabled or not.

Вам также может понравиться