Start Profiling an ASP.NET Core App using IIS Express and .NET Core | .NET Memory Profiler Documentation

Start Profiling an ASP.NET Core App using IIS Express and .NET Core

The easiest way of profiling a .NET Core ASP.NET Core application is by starting the profiler from Visual Studio 2019, e.g. using the command Profiler->Start memory profiler in Visual Studio. For more information, see Start Profiling a Project.

The IIS Express configuration of an ASP .NET Core application in Visual Studio is based on environment variables in the IIS Express application host configuration file, instead of a web.config file for each build output. These environment variable are updated by Visual Studio before launch, to reflect the currently selected build output. Currently it is not possible to initialize these environment variables using .NET Memory Profiler (except by using the command Profiler->Start memory profiler in Visual Studio), so the following procedure is necessary to profile an ASP.NET Core application using the standalone profiler.

  1. Use Visual Studio to publish the ASP.NET Core application to the file system. This will create a runnable version of the ASP.NET Core app, including a web.config file.

  2. Add the location of the published web application as a site in the IIS Express application host configuration file (applicationhost.config). This can be the configuration file for the Visual Studio solution (located in the “.vs” directory of the solution), or the global IIS Express configuration file (located under “C:\Users\<User>\Documents\IISExpress\config”).

    Below you will find an example of the site element. Replace <id> and <path to .NET Core app directory> with suitable values.

    <sites>
      ...
      <site name="PublishedWebApplication1" id="<id>">
        <application path="/" applicationPool="Clr4IntegratedAppPool">
          <virtualDirectory path="/" physicalPath="<path to .NET Core app directory>" />
        </application>
        <bindings>
          <binding protocol="http" bindingInformation="*:53415:localhost" />
        </bindings>
      </site>
      ...
    </sites>
    
  3. In the profiler select Profile ASP.NET and then the Launch using IIS Express option.

  4. Specify the configuration to file to use in the IIS Express config file field. This should be the configuration to which the site information was added.

  5. Select the site that was added to the configuration file (e.g. “PublishedWebApplication”) in the Use IIS Express web site field.

  6. Make sure the Profile as .NET Core application option is selected. This will make sure that the primary process to profile will be the .NET Core process, and not the IIS Express process.

  7. Click Start to start profiling, or Next to specify additional settings.