'jQuery' is undefined


#1

Hello!
I use ASP.NET MVC 4 project.
Install package from Nuget MiniProfiler 2.1.0.
Setup in main page razor view @StackExchange.Profiling.MiniProfiler.RenderIncludes() and in Global.asax Start/Stop.
When load main page raise javascript error ‘jQuery’ is undefined.
It occurs because first load script http://localhost:62928/mini-profiler-resources/includes.js?v=xwYPDDH1blvqmxgsBweNC++H7CFU3KGQ+zFcVlJPsXw=
which contains jQuery call at 897 line ...function(){d.event.special[this]={add:h}})})(jQuery);
But JQuery loaded in next request http://localhost:62928/mini-profiler-resources/jquery.1.7.1.js?v=xwYPDDH1blvqmxgsBweNC++H7CFU3KGQ+zFcVlJPsXw=


#2

In Visual Studio 2012 update 2 create new project: ASP.NET MVC 4 Web Application.
Add HomeController and Index view.
Via NuGet install MiniProfiler.MVC3 package.
In Index view before body tag add @StackExchange.Profiling.MiniProfiler.RenderIncludes().
Open Manage NuGet packages… -> Updates (Stable only) and click Update All button.
Rebuild solution.
Run Ctrl+F5 and get error “Line: 895 Error: ‘jQuery’ is undefined”.


#3

Is this an IE 8 issue?
There is a fix involving wildcard mapping to aspnet_isapi.dll for IIS.
I’m not sure how to map against VS2012’s ASP.NET development server…


#4

Good news for my development machine, I’ve resolved this problem for my ASP.NET Development Server… so far, so good…

I decided to implement MiniProfiler through an HTTP Module in my .NET web forms project, following the guidelines from here http://www.codeproject.com/Articles/246820/Using-MVC-Mini-Profiler-as-a-Http-Module.

In order to solve the exception thrown due to not loading jQuery-1.7.1.js before MiniProfiler was invoked, I added the script to the insertions from the HTTP Module, just before the insertion of the MiniProfiler.Includes().ToHtmlString().

    private string MiniProfiler_jQuery = @"<script type=""text/javascript"" src=""Scripts/jquery-1.7.1.js""></script>";

Here is my ‘Write’ method in MiniProfilerFilterStream.cs that inserts the reference:

public override void Write(byte[] buffer, int offset, int count)
{
if (!profilerHtmlRendered)
{
var responseText = Encoding.UTF8.GetString(buffer, offset, count);

            if (responseText.Contains("</body>"))
            {
                var miniProfilerHtml = MiniProfiler.RenderIncludes().ToHtmlString();
                int index = responseText.IndexOf("</body>") + 8;
                int index2 = index + MiniProfiler_jQuery.Length + 1;
                var newOutput = responseText.Insert(index, MiniProfiler_jQuery).Insert(index2, miniProfilerHtml);
                var newBytes = Encoding.UTF8.GetBytes(newOutput);

                stream.Write(newBytes, 0, newBytes.Length);
                profilerHtmlRendered = true;
                return;
            }
        }

        stream.Write(buffer, offset, count);
    }