Miniprofiler V4 does not render on MVC5 + EF

Asked

Viewed 54 times

2

Good morning, you guys.

I installed the MiniProfiler v4 in my project ASP.NET MVC5 to check some slow points, however, the results screen is not rendered in my view - and no error appears in the Console, just nothing happens.

Anyway, I’m running out of exits. I followed most of the similar topics here and the international Stack, but I couldn’t solve this problem.

Maybe it’s something simple that I can’t see. Can you help me?

Edit: Problem solved. I will keep the full question and my updates until I get to the solution, it can be useful for someone, since the content on Miniprofiller is very sparse.


Installation steps:

  • 1 I installed the MiniProfiler via Nuget; I installed MiniProfilerEF via Nuget;

  • 2 No Global.asax, added some Miniprofiler settings:

In the Application_Start;

    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);


        //Inicialização do MiniProfiler EF
        MiniProfilerEF6.Initialize();
    }

In the Application_BeginRequest;

    protected void Application_BeginRequest()
    {
        //Só faço o Profiling se for uma requisição local
        if (Request.IsLocal)
        {
            MiniProfiler.StartNew();
        }
    }

And, finally, in the Application_EndRequest:

    protected void Application_EndRequest()
    {
        MiniProfiler.Current?.Stop();
    }
  • 3 In the web.config from the root of the project, I set up handlers inside the tag < system.webServer>:

    <handlers><add name="MiniProfiler" path="mini-profiler-resources/*" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" /></handlers>
    
  • 4 No _Layout.cshtml, added the Miniprofiler reference and call:

The reference @using StackExchange.Profiling at the top and in the line before the < /body>, the call of surrender:

@MiniProfiler.Current.RenderIncludes()

  • 5 I executed the project. After these steps, the pop up with statistics should already appear.

Miniprofiler installed packages:

Miniprofiler version="4.0.138" targetFramework="net461"

Miniprofiler.EF version="2.1.0" > targetFramework="net461"

Miniprofiler.EF6 version="4.0.138" targetFramework="net461"

Miniprofiler.Shared version="4.0.138 targetFramework="net461"

AND OF THE MVC:

Microsoft.AspNet.Mvc version="5.2.6" targetFramework="net461"


Additional information

  • I’ve tried reinstalling Miniprofiller;
  • I tried to follow the tutorial described in official website of Miniprofiler
  • I already followed some external tutorials, but few were v4 and none solved the problem;
  • I’ve tried cleaning the solution, recompiling, etc;
  • I’ve done one Update-Package;
  • I already downloaded the full version manager project and tried again.
  • In the source code of the page generated in the browser, the call @MiniProfiler.Current.RenderIncludes() does not generate any code.
  • If I try to access the http://localhost:porta/mini-profiler-resources/includes.js, I get a 404 error, so I guess the problem comes from;
  • In the Browser Console, I have no error.

Updates

  • On 02/10 at 14:23: If I use the @MiniProfiler.Current.RenderPlainText() in the _Layout, I have a rendered text:

DVLP_01 at 02/10/2018 17:21:13 Miniprofiler = ms (sql = 214.4ms in 4 cmds)


  • On 02/10 at 15:23: Debugging @MiniProfiler.Current.RenderIncludes(), I see the call to public static IHtmlString RenderIncludes(...) happens, the variable profiler is filled, but the settings go null, then in the snippet below, the empty string is returned.

if (profiler == null) return _empty; var settings = profiler.Options as MiniProfilerOptions; if (settings == null) return _empty;

I’m researching it now. The problem must be there.


  • On 02/10 at 16:00: Actually, part of the problem was the variable settings null.

I edited the Global.asax adding the configuration of MiniProfilerOptions in the Application_Start:

protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            MiniProfiler.Configure(new MiniProfilerOptions
            {
                // Rota base será ~/profiler, 
                //então teremos /profiler/mini-profiler-includes.js
                RouteBasePath = "~/profiler",

                // Defino para conexões locais
                ResultsAuthorize = request => request.IsLocal,

                //Rastrear abertura e fechamento de conexões
                TrackConnectionOpenClose = true
            }
            //Configurações adicionais
            .AddViewProfiling() //Adiciona um a view MVC view
            );

            //Inicialização do MiniProfilerEF6 (EntityFramework 6)
            MiniProfilerEF6.Initialize();
        }

And, the variable will no longer null and does not return an empty string, but rather the script.

<script async="async" id="mini-profiler" src="/profiler/includes.min.js?v=4.0.138+gcc91adf599" data-version="4.0.138+gcc91adf599" data-path="/profiler/" data-current-id="ad7560c4-69a1-4d6a-a060-cc7629f1d1af" data-ids="dfd38a97-76ce-4915-8a69-63892f510774,e289321b-b7f3-4b64-95a1-d1b102647069,ad7560c4-69a1-4d6a-a060-cc7629f1d1af" data-position="Left" data-authorized="true" data-max-traces="15" data-toggle-shortcut="Alt+P" data-trivial-milliseconds="2.0" data-ignored-duplicate-execute-types="Open,OpenAsync,Close,CloseAsync"></script>

Now we have to find out why it didn’t open. On the Console, I have an error:

Uncaught Syntaxerror: Unexpected token <

  • On 02/10 at 15:50: Problem solved.

I identified that the error described above was caused by having the return 404 in the /profiler/includes.min.js?v=4.0.138+gcc91adf599. This is because when I created the custom configuration on Application_Start, set the course RouteBasePath = "~/profiler", but the path in the web.config remained with mini-profiler-resources/*.

I changed the handlers described in step 3 to:

    <handlers><add name="MiniProfiler" path="profiler/*" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" /></handlers>

and added the filters with the ProfilingActionFilter in the archive FilterConfig:

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
            filters.Add(new ProfilingActionFilter());
        }

And it worked. The file is found and the popup appears!

  • The most interesting would be you keep the original doubt and post the resolution as a response and accept it, this helps in the operation of the site, do not forget to do the [tour] to better understand how Sopt works

  • Barbetta, thank you! My updates were only complementary, I did not change anything in the original question. Do you think I should keep it that way or remove the "Updates" field by adding it in a reply?

  • And one more thing... as you added the comment I wrote the answer. rs I can edit it, if you think it otherwise looks better. Hug!

  • KKK true, it was all together. I think it is valid to remove what solution of the question and keep as an answer, just being marked as correct and having all the content there will help a lot of people, including me who will test this tool :P

1 answer

0


Detailed solution is described in the field Updates of the question itself, but I will add a summary:

  1. Make sure packages are installed correctly;
  2. Make sure that the Application_Start() has profiler configuration and profiler initialization for EF;
  3. Make sure that the web.config has the handlers configured according to the custom path in Application_Start();
  4. Make sure that the ProfilingActionFilter was added in the FilterConfig;

Finally, run the solution by forcing an update (Control+F5) and analyze the results in the Console and Sources. If the file /profiler/includes.min.js is not visible (404 or a custom error page), analyze permission/access restriction rules - probably, something related to point 3 of this reply.

Following these steps I was able to solve the problem here. Read the question carefully and make analogies with your scenario, you’ll probably get it too.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.