Getting "Not Found" error with mini profiler in ASP.NET Core with EF .net 5
Asked Answered
M

1

6

I've added the following code to my asp.net core .net 5 app that works with entity framework. In startup.cs I have:

services.AddMiniProfiler(options =>
        {
            options.PopupRenderPosition = StackExchange.Profiling.RenderPosition.BottomLeft;
            options.PopupShowTimeWithChildren = true;
            options.RouteBasePath = "/profiler";
        }).AddEntityFramework();

and before my app.useRouting I have

app.UseMiniProfiler();

I added to a controller that I know gets called the following:

    using System.Collections.Generic;
    using System.Linq;
    using EFSvcc.Models;
    using Microsoft.AspNetCore.Mvc;
    using StackExchange.Profiling;

    namespace WebAppReactCRA.Controllers
    {
        [ApiController]
        [Route("[controller]")]
        public class WeatherForecastController : ControllerBase
        {
            private readonly svcodecampContext _dbContext;

            public WeatherForecastController(svcodecampContext dbContext)
            {
                _dbContext = dbContext;
            }


            [HttpGet]
            public List<DiscountCode> Get()
            {
                List<DiscountCode> discountCodes;
                using (MiniProfiler.Current.Step("WeatherForecastController: Groupby Clause For Total and Sent"))
                {
                    var z = _dbContext.DiscountCodes;
                    discountCodes = z.ToList();
                }

                return discountCodes;
            }
        }
    }

It's a SPA app so not surprised not to get the popup, but I can't seem to get http://localhost:5000/profiler to work. It just returns "not found"

Thoughts?

Mordant answered 19/12, 2020 at 14:52 Comment(3)
Do you mean 404 Not Found? If so, then I guess that a breakpoint in your Get method will never get hit. Also worth posting your whole Controller to check the routes.Dkl
Thanks @NeilW I updated to include the full controller code. You are right that it is a 404 (I thought that was the profiler returning the text not found). I moved my services.add to the bottom of that method but still getting the 404 on profiler.Mordant
Also, it's the /profiler route that is returning 404. My weather controller is executing.Mordant
D
10

According to this:

https://miniprofiler.com/dotnet/AspDotNetCore

Based on your override of the RouteBasePath, your available routes are:

http://localhost:{port number}/profiler/results-index
http://localhost:{port number}/profiler/results
http://localhost:{port number}/profiler/results?id={guid of specific profiler}

I don't believe a route of just /profiler is actually exposed.

Dkl answered 19/12, 2020 at 16:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.