MiniProfiler Integration with Entity Framework Core
Step 1: Install NuGet packages
dotnet add package MiniProfiler.AspNetCore.Mvc dotnet add package MiniProfiler.EntityFrameworkCore
Step 2: Configure services in Startup.cs (or Program.cs in .NET 6+)
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
// Add MiniProfiler with EF Core
services.AddMiniProfiler(options =>
{
options.RouteBasePath = "/profiler"; // results available at /profiler
}).AddEntityFramework();
}
Step 3: Add MiniProfiler middleware
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
// Enable MiniProfiler
app.UseMiniProfiler();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
Step 4: Add MiniProfiler UI to MVC Layout (Views/Shared/_Layout.cshtml) before the closing </body> tag
@await this.RenderProfilerAsync()