MiniProfiler V4 does not render in MVC5 + EF

2

Good morning, guys.

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

Anyway, I'm running out of time. I followed most of the similar topics here and the International Stack, but I could not solve this problem.

Maybe it's something simple that I can not see. Can you help me?

Edit: Problem solved. I'll keep the whole question and my updates up to the solution, it might be useful for someone, since the content on MiniProfiller is pretty sparse.

Installation steps:

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

  • 2 In Global.asax , I've added some MiniProfiler settings:

No 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();
    }

No Application_BeginRequest ;

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

And, finally, no Application_EndRequest :

    protected void Application_EndRequest()
    {
        MiniProfiler.Current?.Stop();
    }
  • 3 In the% of the root of the project, I made the configuration of handlers within the tag web.config :

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

The reference _Layout.cshtml at the top and, on the line before @using StackExchange.Profiling , the render call:

< /body>

  • 5 I ran the project. After these steps, 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 from MVC:

  

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

Additional information

  • I've tried reinstalling MiniProfiller;
  • I've tried to follow the tutorial described in the official MiniProfiler website
  • I have already followed some external tutorials, but few were from v4 and none solved the problem;
  • I have tried to clean the solution, recompile, etc;
  • I already made a @MiniProfiler.Current.RenderIncludes() ;
  • I've already downloaded the full version manager project and tried again.
  • In the source code of the page generated in the browser, the Update-Package call does not generate any code.
  • If I try to access @MiniProfiler.Current.RenderIncludes() , I get a 404 error, so I guess the problem comes from there;
  • In the browser console, I have no error.

Updates

  

DVLP_01 at 02/10/2018 17:21:13 MiniProfiler = ms (sql = 214,4ms in 4 cmds)

  • On 02/10 at 3:23 PM: Debugging _Layout , I see that the call to @MiniProfiler.Current.RenderIncludes() happens, the variable public static IHtmlString RenderIncludes(...) is filled, but the profiler is null, so in the following section it is returned the empty string.

settings

I'm researching this now. The problem should be there.

  • On 02/10 at 4:00 PM: Really, part of the problem was the variable if (profiler == null) return _empty; var settings = profiler.Options as MiniProfilerOptions; if (settings == null) return _empty; null.

I edited settings by adding the setting of Global.asax to MiniProfilerOptions :

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 no longer goes 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 you have to find out why it did not open. In the Console, I have an error:

  

Uncaught SyntaxError: Unexpected token

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

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

I changed the mini-profiler-resources/* described in step 3 to:

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

and I added the handlers with the filters in the ProfilingActionFilter file:

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!

    
asked by anonymous 02.10.2018 / 16:19

1 answer

0

The detailed solution is described in the Updates field of the question itself, but, I'll add a summary:

  • Make sure the packages have been installed correctly;
  • Make sure that Application_Start() has profiler setup and profiler initialization for EF;
  • Make sure web.config has handlers set to custom path in Application_Start() ;
  • Make sure ProfilingActionFilter was added in FilterConfig ;
  • Finally, run the solution by forcing an update (Control + F5) and analyze the results in Console and Sources. If the /profiler/includes.min.js file is not visible ( 404 or a custom error page), review the access permission / restriction rules - probably something related to point 3 of this answer.

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

        
    02.10.2018 / 22:19