Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mini profiler not displaying ajax request information?

I'm using the mini-profiler on my asp.net MVC 3 application. I've implemented the profiler using the mvc nuget package. Everything works ok for standard page requests i get profile information sql everything.

However ajax requests don't seem to display initially. Just to let me confirm the request are completed without error. I've debugged this and they complete they also return http 200 responses in fiddler.

There is no request by the mini profiler that accompanies the ajax request. When i then navigate to another page i.e. a standard page request all the ajax request that were made on the last page are now displayed.

This is my mini profiler configuration page in App_Start

public static class MiniProfilerPackage
    {
        public static void PreStart()
        {
            //Setup sql formatter
            MiniProfiler.Settings.SqlFormatter = new OracleFormatter();

            //Make sure the MiniProfiler handles BeginRequest and EndRequest
            DynamicModuleUtility.RegisterModule(typeof(MiniProfilerStartupModule));

            //Setup profiler for Controllers via a Global ActionFilter
            GlobalFilters.Filters.Add(new ProfilingActionFilter());

            //Settings            
            MiniProfiler.Settings.PopupShowTimeWithChildren = true;
            MiniProfiler.Settings.PopupShowTrivial = false;            

            //Ignore glimpse details in miniprofiler
            var ignored = MiniProfiler.Settings.IgnoredPaths.ToList();
            ignored.Add("Glimpse.axd");
            MiniProfiler.Settings.IgnoredPaths = ignored.ToArray();
        }

        public static void PostStart()
        {
            // Intercept ViewEngines to profile all partial views and regular views.
            // If you prefer to insert your profiling blocks manually you can comment this out
            var copy = ViewEngines.Engines.ToList();
            ViewEngines.Engines.Clear();
            foreach (var item in copy)
            {
                ViewEngines.Engines.Add(new ProfilingViewEngine(item));
            }
        }
    }

    public class MiniProfilerStartupModule : IHttpModule
    {
        public void Init(HttpApplication context)
        {
            context.BeginRequest += (sender, e) =>
            {
                var request = ((HttpApplication)sender).Request;

                MiniProfiler.Start();
            };

            //Profiling abadened if user is not in the admin role
            context.PostAuthorizeRequest += (sender, e) =>
            {
                if (!context.User.IsInRole("Admin"))
                    MiniProfiler.Stop(discardResults: true);
            };

            context.EndRequest += (sender, e) =>
            {
                MiniProfiler.Stop();
            };
        }

        public void Dispose() { }
    }

Is there some configuration that is required or potential issues I should be aware of?

like image 621
Richard Forrest Avatar asked Feb 22 '23 07:02

Richard Forrest


1 Answers

In the end i figured out that the Miniprofiler JavaScript block that is added to the page must be below the pages jquery reference.

My JavaScript reference are all added at the end of the page for best practice performance reasons.

But I'd left the @MvcMiniProfiler.MiniProfiler.RenderIncludes() in the page header. Moving it below the jquery script ref at the bottom of the page fixed my problem.

like image 121
Richard Forrest Avatar answered Mar 05 '23 22:03

Richard Forrest