Isolating ASP .Net 2.0 Applications - Trace

how-to | home

Using Trace With the Example HTTP Module

The debug version of AspManifestHelpers.dll is built with trace turned on. To activate the trace copy the debug version of the DLL to your .\bin folder and edit your web.config file to add the following entries:

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  [...]
  <system.web>
    [..]
    <trace enabled="true" pageOutput="false" writeToDiagnosticsTrace="true"/>
  </system.web>

<system.diagnostics>
  <trace autoflush="true">
    <listeners>
      <add name="WebPageTraceListener"
           type="System.Web.WebPageTraceListener, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
      <add name="TestTracer"
           type="System.Diagnostics.TextWriterTraceListener, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
           initializeData="C:\Temp\aspnet20trace.log" />
    </listeners>
  </trace>
</system.diagnostics>
</configuration>

You may already have the <system.diagnostics> or the <trace enabled="true"/> element in the web.config. You can configure the trace any way is convenient for your installation. This example picks up both the ASP.Net web page trace output and the example HTTP module trace output and directs both of them to the same file. Make sure the trace file path you specify in the initializeData attribute is valid and can be written to by ASP.Net. The trace file content will look somewhat like the following example:

HttpModule_ProcessManifest: 3/28/2008 20:35:12; Init;
  manifest=C:\Temp\Asp.Net.20\DropInManifest\webapp.manifest;
  Activation context created.
aspx.page: Begin PreInit
aspx.page: End PreInit
aspx.page: Begin Init
aspx.page: End Init
aspx.page: Begin InitComplete
aspx.page: End InitComplete
aspx.page: Begin PreLoad
aspx.page: End PreLoad
aspx.page: Begin Load
aspx.page: End Load
aspx.page: Begin LoadComplete
aspx.page: End LoadComplete
aspx.page: Begin PreRender
aspx.page: End PreRender
aspx.page: Begin PreRenderComplete
aspx.page: End PreRenderComplete
aspx.page: Begin SaveState
aspx.page: End SaveState
aspx.page: Begin SaveStateComplete
aspx.page: End SaveStateComplete
aspx.page: Begin Render
aspx.page: End Render
aspx.page: Begin PreInit
aspx.page: End PreInit
aspx.page: Begin Init
aspx.page: End Init
aspx.page: Begin InitComplete
aspx.page: End InitComplete
aspx.page: Begin LoadState
aspx.page: End LoadState
aspx.page: Begin ProcessPostData
aspx.page: End ProcessPostData
aspx.page: Begin PreLoad
aspx.page: End PreLoad
aspx.page: Begin Load
aspx.page: End Load
aspx.page: Begin ProcessPostData Second Try
aspx.page: End ProcessPostData Second Try
aspx.page: Begin Raise ChangedEvents
aspx.page: End Raise ChangedEvents
aspx.page: Begin Raise PostBackEvent
aspx.page: End Raise PostBackEvent
aspx.page: Begin LoadComplete
aspx.page: End LoadComplete
aspx.page: Begin PreRender
aspx.page: End PreRender
aspx.page: Begin PreRenderComplete
aspx.page: End PreRenderComplete
aspx.page: Begin SaveState
aspx.page: End SaveState
aspx.page: Begin SaveStateComplete
aspx.page: End SaveStateComplete
aspx.page: Begin Render
aspx.page: End Render

The first line in the trace states that the context was successfully created. If there is a *.exe.manifest file for the executable that is hosting your application, you will see message Activation context already existed which means that your manifest is not being used.

Note: The development web server used by Visual Studio 2005 has an external manifest file (WebDev.WebServer.exe.manifest) which contains only a reference to Common Controls 6. You need to rename that file to test this solution using this web server. The example HTTP module silently ignores this error and writes a trace file entry similar to the following:

HttpModule_ProcessManifest: 3/28/2008 20:35:12; Init;
  manifest=C:\Temp\Asp.Net.20\DropInManifest\webapp.manifest;
  Activation context already existed.

If web.manifest does not exist, the example HTTP module throws an exception which writes the following into the trace file:

HttpModule_ProcessManifest: HttpModule_ProcessManifest.Init:
  Cannot create process-default win32 sxs context,
  error=2 manifest=C:\Temp\Asp.Net.20\DropInManifest\webapp.manifest
  url=http://localhost:1499/DropInManifest/default.aspx

Note that error=2 indicates Windows error code 2 (ERROR_FILE_NOT_FOUND).


Read more: