-1

I followed the setup instructions here https://miniprofiler.com/dotnet/AspDotNetCore and got Mini Profiler working with my ASP.NET core web app. I pushed the code up to my staging site and now see the output on every request.

Previously local only access was documented here https://miniprofiler.com/

using StackExchange.Profiling;
...    
protected void Application_BeginRequest()
{
    if (Request.IsLocal)
    {
        MiniProfiler.Start();
    } 
}

How can I restrict miniprofiler to only show for local requests in ASP.NET core

Brad Patton
  • 4,007
  • 4
  • 34
  • 44

1 Answers1

0

From the documentation:

services.AddMiniProfiler(options =>
{
    // (Optional) To control authorization, you can use the Func<HttpRequest, bool> options:
    // (default is everyone can access profilers)
    options.ResultsAuthorize = request => CanAccessMiniProfiler(request);
    options.ResultsListAuthorize = request => CanAccessMiniProfiler(request);
}

You can implement it any way you like:

private bool CanAccessMiniProfiler(HttpRequest request)
{
    // Add your logic here, e.g. check for local requests and certain roles
}
Henk Mollema
  • 44,194
  • 12
  • 93
  • 104
  • I missed that. I was looking for something like the original example that had a check for Request.IsLocal (https://miniprofiler.com/). It's surprising difficult to check for if the Request is local in .net core – Brad Patton Jun 20 '18 at 18:23
  • 1
    You could consider using `IHostingEnvironment.IsDevelopment()` in stead of determining if the request is a local URL. – Henk Mollema Jun 20 '18 at 18:30