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