Dela via


How to: Modify Web.Config Files to Instrument and Profile Dynamically Compiled ASP.NET Web Applications

You can use the Visual Studio Team System Developer Edition Profiling Tools instrumentation method to collect detailed timing data, .NET memory allocation data, and .NET object lifetime data from dynamically compiled ASP.NET Web applications.

This topic describes how to modify the web.config configuration file to enable the instrumentation and profiling of ASP.NET Web applications.

Note

You are not required to modify the web.config file when you use the sampling profiling method, or when you want to instrument a pre-compiled ASP.NET module.

The root of a web.config file is the configuration element. To instrument and profile a dynamically compiled ASP.NET Web application, you must add or modify the following elements:

  • A configuration/runtime/assemblyBinding/dependentAssembly element that identifies the Microsoft.VisualStudio.Enterprise.ASPNetHelper assembly that controls profiling. The dependentAssembly element contains two child elements: assemblyIdentity and codeBase.

  • A configuration/system.web/compilation element that identifies the profiler post-process compilation step for the target assembly.

  • Two add elements that identify the location of the Profiling Tools tools are added to the configuration/appSettings section .

We recommend that you create a copy of the original web.config file that you can use to restore the configuration of the application.

To add the ASPNetHelper assembly as a configuration/runtime/assemblyBinding/dependentAssembly element

  1. If necessary, add the runtime element as a child element of the configuration element; otherwise, go to the next step.

    The runtime element has no attributes. The configuration element can have only one runtime child element.

  2. If necessary, add the assemblyBinding element as a child element of the runtime element; otherwise, go to the next step.

    The runtime element can have only one assemblyBinding element.

  3. Add the following attribute name and value to the assemblyBinding element:

    Attribute Name

    Attribute Value

    Xmlns

    urn:schemas-microsoft-com:asm.v1

  4. Add a dependentAssembly element as a child element of the assemblyBinding element.

    The dependentAssembly element has no attributes.

  5. Add an assemblyIdentity element as a child of the dependentAssembly element.

  6. Add the following attribute names and values to the assemblyIdentity element:

    Attribute Name

    Attribute Value

    name

    Microsoft.VisualStudio.Enterprise.ASPNetHelper

    PublicKeyToken

    b03f5f7f11d50a3a

    culture

    Neutral

  7. Add a codeBase element as a child of the dependentAssembly element.

  8. Add the following attribute names and values to the codeBase element:

    Attribute Name

    Attribute Value

    version

    9.0.0.0

    href

    PathToASPNetHelperDll

    PathToASPNetHelperDll is the file URL of the Microsoft.VisualStudio.Enterprise.ASPNetHelper.dll. If Visual Studio is installed in the default location, the href value should be file:///C:/Program%20Files/Microsoft%20Visual%20Studio%209.0/Common7/IDE/PrivateAssemblies/Microsoft.VisualStudio.Enterprise.ASPNetHelper.DLL

    <configuration>
        <runtime>
            <assemblyBinding 
                xmlns="urn:schemas-microsoft-com:asm.v1"
            >
                <dependentAssembly>
                    <assemblyIdentity                         name="Microsoft.VisualStudio.Enterprise.ASPNetHelper" 
                        publicKeyToken="b03f5f7f11d50a3a"                         culture="neutral" 
                    />
                    <codeBase 
                        version="9.0.0.0"
                        href="file:///C:/Program%20Files/Microsoft%20Visual%20Studio%209.0/Common7/IDE/PrivateAssemblies/Microsoft.VisualStudio.Enterprise.ASPNetHelper.DLL" 
                    />
                </dependentAssembly>
            </assemblyBinding>
        </runtime>

To add the Profiler post-process step to the configuration/system.web/compilation element

  1. If necessary, add the system.web element as a child element of the configuration element; otherwise, go to the next step.

    The system.web element has no attributes. The configuration element can have only one system.web child element.

  2. If necessary, add the compilation element as a child element of the system.web element; otherwise, go to the next step.

    The system.web element can have only one compilation child element.

  3. Remove any existing attributes from the compilation element, and add the following attribute name and value:

    Attribute Name

    Attribute Value

    assemblyPostProcessorType

    Microsoft.VisualStudio.Enterprise.Common.AspPerformanceInstrumenter, Microsoft.VisualStudio.Enterprise.ASPNetHelper, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

    <configuration>
        <runtime>
        . . .
        </runtime>
        <system.web>
            <compilation
                assemblyPostProcessorType="Microsoft.VisualStudio.Enterprise.Common.AspPerformanceInstrumenter,
                    Microsoft.VisualStudio.Enterprise.ASPNetHelper,
                    Version=9.0.0.0,
                    Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
            />
        </system.web>
    <configuration>

To add Profiler location settings to the configuration/appSettings element

  1. If necessary, add the appSettings element as a child element of the configuration element; otherwise, go to the next step.

    The appSettings element has no attributes. The configuration element can have only one appSettings child element.

  2. Add an add element as a child of the appSettings element.

  3. Add the following attribute names and values to the add element:

    Attribute Name

    Attribute Value

    key

    Microsoft.VisualStudio.Enterprise.AspNetHelper.VsInstrLocation

    value

    PerformanceToolsFolder\VSInstr.Exe

  4. Add another add element as a child of the appSettings element.

  5. Add the following attribute names and values to this add element:

    Attribute Name

    Attribute Value

    key

    Microsoft.VisualStudio.Enterprise.AspNetHelper.VsInstrTools

    value

    PerformanceToolsFolder

    PerformanceToolsFolder is the path of the profiler executable files. If Visual Studio is installed in the default location, the value will be C:\Program Files\Microsoft Visual Studio 9.0\Team Tools\Performance Tools

    <configuration>
        <runtime>
        . . .
        </runtime>
        . . .
        <system.web>
        </system.web>
        <appSettings>
            <add
                key="Microsoft.VisualStudio.Enterprise.AspNetHelper.VsInstrLocation"
                value="C:\Program Files\Microsoft Visual Studio 9.0\Team Tools\Performance Tools\vsinstr.exe"
        />
            <add
                key="Microsoft.VisualStudio.Enterprise.AspNetHelper.VsInstrTools"
                value="C:\Program Files\Microsoft Visual Studio 9.0\Team Tools\Performance Tools\"
            />
        </appSettings>
    </configuration>

Example

The following is a complete web.config file that enables the instrumentation and profiling of dynamically compiled ASP.NET Web applications. This example assumes that there were no other settings in the file before modification.

<?xml version="1.0"?>
    <configuration>
        <runtime>
            <assemblyBinding 
                xmlns="urn:schemas-microsoft-com:asm.v1"
            >
                <dependentAssembly>
                    <assemblyIdentity                         name="Microsoft.VisualStudio.Enterprise.ASPNetHelper" 
                        publicKeyToken="b03f5f7f11d50a3a"                         culture="neutral" 
                    />
                    <codeBase 
                        version="9.0.0.0"
                        href="file:///C:/Program%20Files/Microsoft%20Visual%20Studio%209.0/Common7/IDE/PrivateAssemblies/Microsoft.VisualStudio.Enterprise.ASPNetHelper.DLL" 
                    />
                </dependentAssembly>
            </assemblyBinding>
        </runtime>
        <system.web>
            <compilation
                assemblyPostProcessorType="Microsoft.VisualStudio.Enterprise.Common.AspPerformanceInstrumenter,
                    Microsoft.VisualStudio.Enterprise.ASPNetHelper,
                    Version=9.0.0.0,
                    Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
            />
        </system.web>
        <appSettings>
            <add
                key="Microsoft.VisualStudio.Enterprise.AspNetHelper.VsInstrLocation"
                value="C:\Program Files\Microsoft Visual Studio 9.0\Team Tools\Performance Tools\vsinstr.exe"
        />
            <add
                key="Microsoft.VisualStudio.Enterprise.AspNetHelper.VsInstrTools"
                value="C:\Program Files\Microsoft Visual Studio 9.0\Team Tools\Performance Tools\"
            />
        </appSettings>
    </configuration>

See Also

Tasks

How to: Instrument a Dynamically Compiled ASP.NET Web Application and Collect Detailed Timing Data with the Profiler by Using the Command Line

How to: Instrument a Dynamically Compiled ASP.NET Web Application and Collect Memory Data by Using the Profiler Command Line