Sunday, March 21, 2010

.NET 4 Debugging 70-515 Exam Prep ASP.NET troubleshooting & monitoring

.NET 4 Debugging 70-515 Exam Prep ASP.NET troubleshooting & monitoring

Hey Now Everybody,

Microsoft announced the .NET 4.0 Beta Exams on St. Patrick’s Day which are a free exam & if passed you get certified. Much of the study & prep materials are not available yet, therefore I’ve been studying for a similar exam 70-562 which is the .NET 3.5 ASP.NET Application Development. I hope by posting this content it will help myself along with other people in the community learn & get excited about .NET 4.

In this 4th post of the series  (maybe gonna name it Catto’s Code Crackin) we’ll continue with the section debugging & monitoring. In the .NET 3.5 exam troubleshooting, debugging & monitoring are ~16%. In the .NET 4 exam there is not a section dedicated to debugging however one bullet point of the ‘Configuring & Extending a Web Application’ section reads:

Debug a Web application.
This objective may include but is not limited to: remote, local, JavaScript debugging, attaching to process, logging and tracing, using local IIS, aspnet_regiis.exe

Key points from the chapter in the book are:

o You can turn on debugging for your Web apps inside the web.config file by setting the debug attribute of the compilation element to true. You can also turn on debugging at the individual page level using the debug attribute of the @ Page directive.

o You can set a custom error page for your entire site by setting the defaultRedirect attribute of the customErrors element. You can also map specific pages to HTTP status codes using the errors child element.

o The Remote Debugging monitor (Msvsmon.exe) allows you to configure debugging on a remote server.

o You can use ASP.NET tracing to troubleshoot and diagnose probs with a page in your web site. In outputs info about the request, response and the environment.

o You can use the trace method to output custom trace messages to trace log.

o An AJAX page can use the client side Sys.Debug.trace method to output tracing info to a web page.

o ASP.NET provides health monitoring tools System.WebManagement to enable you to monitor a running Web application. You can configure Web events with listeners through rule child elements of the healthMonitoring element inside Web.config

Let’s continue with some key points from practice exams:

1 When multiple versions of the .NET Framework are executing side by side on a single computer, the ASP.NET Internet Server Application Programming Interface (ISAPI) version mapped to an ASP.NET application determines which version of the common language runtime (CLR) is used for the application. The ASP.NET IIS Registration tool (Aspnet_regiis.exe) allows an administrator or installation program to easily update the script maps for an ASP.NET application to point to the ASP.NET ISAPI version that is associated with the tool.

3 You must run Aspnet_regsql.exe, which is found in %windows%\Microsoft .NET\Framework\<version>. Then you run the tool to create the schema needed by the SQL Server membership provider.

4 When examining data posted to the webserver. The trace result section we can use is the Form Collection section since it contains the posted data.

5 You can use ASP.NET tracing to view page life cycle timings.

6 Setting debug to false inside the compilation element of Web.config will turn off debugging for the entire site.

Setting the debug attribute of the @Page directive to true will turn on debugging just for the selected page.

7 To configure ASP.NET Health monitoring to log info every time a user fails to login to the server. WebAuthenticationSuccessAuditEvent -This class will send an event when a user successfully authenticates with the Web application.

8 When there is an error that is occurring when the app is deployed to the dev server. We can debug this error remotely.

A Running the Remote Debugging Monitor on the server will allow remote debugging for a given user with the appropriate rights.

B You need to attach to the process on the server that is hosting the application.

9 To redirect users to a default error page if they hit any unhandled exceptions or HTTP errors within the site

A The defaultRedirect attribute of the customErrors element will set a default sitewide error page.
B You can use the aspxerrorpath query string parameter to retrieve the requested page to display on the default error page.

10 if we want to run the trace continuously to enable you to quickly look at the 10 most recent traces from anyone using your Web site, but you are concerned about filling your hard drive with excessive data

<trace

enabled="true"

requestLimit="10"

pageOutput="false"

traceMode="SortByTime"

localOnly="false"

mostRecent="true" />

11 ASP.NET provides the Sys.Debug class for debugging client applications. You can call methods of the Sys.Debug class to can display objects in readable form at the end of the page, show trace messages, use assertions, and break into the debugger. If you are using Microsoft Visual Studio and Microsoft Internet Explorer, you can attach the Visual Studio debugger to the browser and view debugger trace messages in the Output window. If you are not using Visual Studio, you can view debugger trace messages in Internet Explorer by creating a textarea element on the page and setting its ID to TraceConsole.

12 You must configure the Web application so that the Trace.axd page will show the last 100 page requests.

<trace

enabled="true"

requestLimit="100"

pageOutput="false"

traceMode="SortByTime"

localOnly="true"

mostRecent="true"

/>

13 The ASP.NET tracing mechanism writes messages that are displayed on ASP.NET Web pages and on the ASP.NET Trace viewer (Trace.axd), whereas the Trace class is used to write trace messages to the standard .NET Framework trace output (typically a console window). To make it easier to track how the Web Forms interact with business objects and other components, you can integrate ASP.NET tracing output with System.Diagnostics tracing to route all tracing messages to one of these outputs.

14 To debug a process that is running under another account name, you must have Administrator privileges on the remote computer. If the ASP.NET worker process aspnet_wp.exe is running as SYSTEM or ASPNET, for example, you have to be an administrator on the computer where that process is running.

15 Web application that uses cookies to track user preferences, troubleshoot , the Web browser does not seem to be correctly submitting the cookie to the Web server.

Trace.axd displays all cookies that the Web browser submits to the Web server. This enables you to determine quickly whether a cookie is working properly.

16 When deploying an ASP.NET app you must choose a performance counter to determine if the webserver is processing requests fast enough. Requests Queued counter will increase only when the Web server cannot process requests faster than they are submitted. Therefore, it is the best gauge of whether the Web server can keep up with demand.

17 For debugging in ASP.NET and other server environments, you can run the Remote Debugging Monitor as a Windows service (the Remote Debugger Service). To configure the Remote Debugging Monitor as a service, use the Visual Studio 2008 Remote Debugger Configuration Wizard and follow the steps in the wizard to set up remote debugging as a service.

18 Use the TraceContext.Write method to write to the page's tracing information. The Page object includes a Trace property that references the TraceContext instance.

19 To enable tracing for an application, add <trace enabled="true"/> to the application's Web.config file in the <configuration><system.web> section.

20 ASP.NET provides the Sys.Debug class for debugging client applications. You can call methods of the Sys.Debug class to display objects in readable form at the end of the page, show trace messages, use assertions, and break into the debugger. If you are using Microsoft Visual Studio and Microsoft Internet Explorer, you can attach the Visual Studio debugger to the browser and view debugger trace messages in the Output window. If you are not using Visual Studio, you can view debugger trace messages in Internet Explorer by creating a textarea element on the page and setting its ID to TraceConsole.

21 WebSuccessAuditEvent provides information about successful security events, including successful URL authorization.

22 For errors that your code handles, you should call the Server.ClearError method. This ensures configured redirection is circumvented.

23 The simplest way to indicate a redirection target is to do so declaratively in the @Page markup.

24 Code for the following tasks:

* Display a page named PageNotFound.aspx if a page causes a 404 error.

* Display a page named Error.aspx for any other page error

<customErrors mode="On" defaultRedirect="~/Error.aspx">

<error statusCode="404" redirect="~/PageNotFound.aspx" />

</customErrors>

25. Intermittent exceptions on an ASP.NET app & remote debugging stops responding when you attempt to debug from your machine. On the test server, grant the Remote Debugging Monitor permission to configure the firewall by confirming in the User Account Control dialog box.

26 To create and install a custom performance counter, call the PerformanceCounterCategory.Create method. Ensure that you call this method once only by including it in your application install or by checking if the performance counter exists before calling.

Call the following code once only:

CounterCreationDataCollection counterDatas = new CounterCreationDataCollection();

CounterCreationData cd = new CounterCreationData();

cd.CounterName = "Shopping cart values";

cd.CounterType = PerformanceCounterType.NumberOfItems64;

counterDatas.Add(cd);

PerformanceCounterCategory.Create("Contoso Storefront", _

"Category help", PerformanceCounterCategoryType.SingleInstance, _

counterDatas);

27 Using impersonation, ASP.NET applications can optionally execute the processing thread using the identity of the client on whose behalf they are operating.

28 WebApplicationLifetimeEvent represents events that affect the life cycle of an ASP.NET application, including events such as application startup and shutdown events. If an application is terminated, you can determine why by viewing the related event message field.

29 Provide an error-handling callback function to the autogenerate Web service proxy, passing parameters in the order echoElem.value, SucceededCallback, and ErrorCallback. Handle exceptions in this method.

Samples.AspNet.SimpleWebService.EchoInput(echoElem.value,

SucceededCallback, ErrorCallback);

30 The .NET Framework 3.5 is not a stand-alone framework like version 2.0 or version 1.1. It is just an extension of the 2.0 Framework. The .NET Framework does not ship with an Aspnet_regiis.exe implementation and there is no new Internet Server Application Programming Interface DLL specific to version 3.5. To use new language features you must configure the 3.5 version of the compiler as shown.

<compiler language=..., Version=2.0.0.0, Culture=neutral,

PublicKeyToken=...>

<providerOption name="CompilerVersion" value="v3.5"/>

</compiler>

31 Configuring remoteOnly mode in the <customErrors> element of the Web.config file specifies that custom errors are shown only to remote clients and ASP.NET errors are shown to the local host.

32 To create a debug compilation, set the debug attribute of the compilation element to True.

<compilation defaultLanguage=".." debug="true">

</compilation>

33 With the Microsoft Visual Studio debugger, you can debug a Web application transparently on the local computer or a remote server. This means that the debugger functions the same way and allows you to use the same features on either computer. For remote debugging to work correctly, however, there are some prerequisites. The Visual Studio Remote Debugging Monitor must be installed on the server you want to debug.

Install the Remote Debugging Monitor (Msvsmon.exe) on the remote computer.

34 Configure rules to map an event set defined in the <eventMappings> section with a log source defined in the <providers> section.

35 A page has JavaScript calls & you must choose a location to add code to capture& log js exceptions. We can add an event handler to the window's onerror event.

The onerror event fires when an error occurs during object loading or run-time scripts.

37 You must explicitly deny unauthorized users to force a redirect to a Forms authentication login page. Do this by adding a deny element to the Web.config authorization element. Set the users attribute to "?"

<authorization>

<deny users="?" />

</authorization>

38 To enable tracing for a single page only add a Trace attribute to the @ Page directive and set its value to True.

39 To debug client script, you must attach a debugger to Internet Explorer. You can attach the Visual Studio debugger to Internet Explorer when the application is already running. To do so, from the Debug menu, select Attach To Process . . . . In the Attach To Process dialog box, select the instance of Internet Explorer (Iexplore.exe) to which you want to attach the debugger. If Internet Explorer encounters a script error and is configured for script debugging, but it is not currently attached to a debugger, the browser prompts you to select a debugger. You can either continue without debugging or attach a debugger and step through the code.

40 Configure the SqlWebEventProvider. This built-in provider will log Web events to a SQL Server database.

41 AutoEventWireup page events must be named in the format Page_Event. In this case, the event is Error (ex Page_Erro). Adding this method will ensure your application catches all unhandled exceptions.

42 ASP.NET provides the Sys.Debug class for debugging client applications. You can call methods of the Sys.Debug class to can display objects in readable form at the end of the page, show trace messages, use assertions, and break into the debugger. If you are using Visual Studio and Internet Explorer, you can attach the Visual Studio debugger to the browser and view debugger trace messages in the Output window.

We’ve covered Troubleshooting, debugging & monitoring ASP.NET applications. After putting this post together in the future some more good content would be creating some sample code to show break points & how VS10 can debug backwards. I’m really looking forward to the next section which we’ll cover ‘Working with Data & Services’. Data is very fun to work with & enables us to deliver data driven applications.

What are your thoughts of debugging code?

That is all & there will be more,

Catto

No comments: