How to use Glimpse in ASP.NET Core

By FoxLearn 1/4/2025 2:17:55 AM   62
Glimpse is an open-source debugging and diagnostics tool for ASP.NET Core web applications.

It provides insights into the performance of ASP.NET and ASP.NET MVC apps. The tool integrates with Application Insights and features an intuitive user interface, allowing developers to examine performance data. Glimpse adds a widget to web pages, similar to MiniProfiler, so that developers can view performance metrics as they navigate through the application.

To use Glimpse in an ASP.NET Core project, you can install Glimpse via NuGet, right-click on your project in the Solution Explorer, then choose "Manage NuGet Packages…". Next, search for "Glimpse.Mvc5" and click the Install button.

Start the ASP.Net Core application and turn on Glimpse

After installing and configuring Glimpse, you can begin using it by starting the application.

To enable Glimpse, navigate to the URL host/Glimpse.axd and click the "Turn Glimpse On" button in the top-right corner of the page.

After enabling Glimpse, a "g" icon will appear at the bottom-right of your application's homepage, along with a Glimpse bar at the bottom of the page. Clicking the "g" icon reveals detailed execution information.

View details of an application in Glimpse tabs

Glimpse offers several tabs to display detailed information about your application, including:

  • Configuration: Details about the machine configuration.
  • Environment: Information about the server handling the request.
  • Execution: Execution metrics like request time.
  • Metadata: Information on the controller, action, and other metadata.
  • Model Binding: Data on model binding, if used.
  • Request: Exact data received by the server.
  • Routes: Registered routes in the application.
  • Server: HTTP variables and their values.
  • Session: Session data, if enabled.
  • Timeline: A timeline of method calls made to render the page.
  • Trace: Trace information from your application.
  • Views: Details on views and view engines.

Add Glimpse to your ASP.NET Core application

After installing Glimpse in your ASP.Net Core project, you can add it to the pipeline by writing the appropriate code in the ConfigureServices method of the Startup class.

public void ConfigureServices(IServiceCollection services)
{
    if (this.HostingEnvironment.IsDevelopment())
    {
        services.AddGlimpse();
    }
}

Next, configure Glimpse in the Configure method:

public void Configure(IApplicationBuilder applicationBuilder, ILoggerFactory loggerFactory)
{
    if (this.HostingEnvironment.IsDevelopment())
    {
        applicationBuilder.UseGlimpse();
    }
}

Make sure to reference the Glimpse assembly in the Startup class.

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }
    public IConfiguration Configuration { get; }
    
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddGlimpse();
        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
    }
    
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseGlimpse();
        }
        app.UseMvc();
    }
}

Glimpse is a free, open-source diagnostics tool that provides valuable performance insights for ASP.NET and ASP.NET Core applications, making debugging easier by inspecting web requests and offering diagnostic tools.