8

My web.config file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <configSections>
    <section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
  </configSections>
  <system.web>
    <customErrors mode="On" redirectMode="ResponseRewrite">
      <error statusCode="500" redirect="~/Content/ErrorPages/500.aspx" />
      <error statusCode="404" redirect="~/Content/ErrorPages/404.aspx" />
    </customErrors>
    <compilation debug="true" targetFramework="4.5.1" />
    <httpRuntime targetFramework="4.5.1" />
    <httpModules>
      <add type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" name="UrlRewriter" />
    </httpModules>
  </system.web>
  <rewriter configSource="Config\URLRewrites.config" />
  <appSettings configSource="Config\Settings.config" />
    <system.webServer>
      <validation validateIntegratedModeConfiguration="false" />
      <httpErrors errorMode="Custom">
            <remove statusCode="500" subStatusCode="-1" />
            <remove statusCode="404" subStatusCode="-1" />
            <error statusCode="404" path="/Content/ErrorPages/404.aspx" responseMode="ExecuteURL" />
            <error statusCode="500" path="/Content/ErrorPages/500.aspx" responseMode="ExecuteURL" />
        </httpErrors>
        <modules runAllManagedModulesForAllRequests="true">
          <remove name="UrlRewriter" />
          <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule,Intelligencia.UrlRewriter" preCondition="managedHandler" />
        </modules>
      <handlers>
        <add name="MiniProfiler" path="mini-profiler-resources/*" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
      </handlers>
    </system.webServer>    
</configuration>

My global.asax:

using System;
using System.Web;
using StackExchange.Profiling;

namespace C3
{
    public class Global : HttpApplication
    {
        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            // Force to HTTPS
            if (!HttpContext.Current.Request.IsSecureConnection)
            {
                Response.Redirect(Settings.SecureRootDomain + HttpContext.Current.Request.RawUrl);
            }

            if (Request.IsLocal)
            {
                MiniProfiler.Start();
            } 
        }

        protected void Application_EndRequest()
        {
            MiniProfiler.Stop();
        }
    }
}

Content page:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="C3.Default"%>
<%@ Import Namespace="C3.Code" %>
<%@ Import Namespace="StackExchange.Profiling" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <%
        SEO.CheckURL("/");
    %>
    <title></title>
    <%=MiniProfiler.RenderIncludes() %>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        dum de dum
    </div>
    </form>

</body>
</html>

And code behind:

protected void Page_Load(object sender, EventArgs e)
{
    var profiler = MiniProfiler.Current; // it's ok if this is null
    using (profiler.Step("Set page title"))
    {
        Page.Title = "Home Page";
    }
    using (profiler.Step("Doing complex stuff"))
    {
        using (profiler.Step("Step A"))
        { // something more interesting here
            Thread.Sleep(100);
        }
        using (profiler.Step("Step B"))
        { // and here
            Thread.Sleep(250);
        }
    }
}

Any ideas why the MiniProfiler isn't showing anything?

Update

If I visit https://127.0.0.1:3333/mini-profiler-resources/includes.js in my browser, it's returning the JS file! It's just not rendering the includes on the page itself.

If I visit /mini-profiler-resources/results it throws the error:

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
StackExchange.Profiling.MiniProfilerHandler.GetSingleProfilerResult(HttpContext context) in c:\TeamCity\buildAgent\work\1de24adb938b932d\StackExchange.Profiling\MiniProfilerHandler.cs:292 StackExchange.Profiling.MiniProfilerHandler.ProcessRequest(HttpContext context) in c:\TeamCity\buildAgent\work\1de24adb938b932d\StackExchange.Profiling\MiniProfilerHandler.cs:93 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +912 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +164

Tom Gullen
  • 61,249
  • 84
  • 283
  • 456
  • 1
    Did you see this github issue? The exception is thrown exactly the same way. https://github.com/MiniProfiler/dotnet/issues/96 – Andrei Jul 29 '15 at 12:55
  • @Andrei yes have seen that, if I add it in it stops the 500 exception but now returns a 404. Includes still not being rendered on the page either. – Tom Gullen Jul 29 '15 at 12:56
  • I'd say 500 -> 400 is an improvement. It might be the case that something else is also wrong, but I'd keep this fix – Andrei Jul 29 '15 at 12:57
  • @Andrei yeah you're probably right. Searched Google for hours, not entirely sure where to go next with this issue – Tom Gullen Jul 29 '15 at 13:02
  • Going forward, all examples I found so far had jquery on the page registered already. You don't have one. It should not be an issue really, but just out of curiosity try passing into `RenderIncludes` the param `useExistingjQuery:false` – Andrei Jul 29 '15 at 13:08
  • check this url: http://miniprofiler.com/ , I believe same method as mentioned in the answer below – user5135401 Jul 29 '15 at 13:09
  • @Andrei param makes no difference – Tom Gullen Jul 29 '15 at 13:13
  • @HadiHassan used `for (int i = 0; i < 100000; i++) { Response.Write(i); }`, no difference nothing rendering – Tom Gullen Jul 29 '15 at 13:14
  • Can you check to see whether `MiniProfiler.Current` has a value or if it's null in `Page_Load`? – Hack Jul 29 '15 at 13:22
  • @Hack, it's `null` after started in global.asax, before I stop it in global.asax, and on the content page (null everywhere!) – Tom Gullen Jul 29 '15 at 13:29
  • @TomGullen, what's the full URL to that Default.aspx page? Does it happen to have /content/ in the URL, e.g. /content/Default.aspx? – Hack Jul 29 '15 at 13:39
  • @Hack, the URL in the browser is `https://127.0.0.1:3333/` but it's rewritten with the rule ``. Is the `Content` directory causing some sort of conflict? – Tom Gullen Jul 29 '15 at 13:41
  • 1
    @Hack, you're a genius! Renamed the folder to `Pages` and it works! Please write this as an answer and I'll accept it :D – Tom Gullen Jul 29 '15 at 13:42

1 Answers1

3

Ensure pages showing the MiniProfiler don't contain an ignored path in the URL specified by MiniProfiler.Settings.IgnoredPaths, which by default has /content/, /scripts/ and /favicon.ico. A page with the URL /content/Default.aspx won't show the MiniProfiler, whereas /Pages/Default.aspx will show it.

Alternatively, remove /content/ from MiniProfiler.Settings.IgnoredPaths.

Hack
  • 1,408
  • 10
  • 13