无法让MVC MiniProfiler在ASP.net网站上展示

时间:2015-07-27 12:29:19

标签: asp.net mvc-mini-profiler

我的web.config文件:

<?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>

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

内容页面:

<%@ 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>

代码背后:

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

为什么MiniProfiler没有显示任何内容?

更新

如果我在浏览器中访问https://127.0.0.1:3333/mini-profiler-resources/includes.js,它将返回JS文件!它只是不在页面上呈现包含。

如果我访问/mini-profiler-resources/results,则会抛出错误:

  

对象引用未设置为对象的实例。

     

描述:执行期间发生了未处理的异常   当前的网络请求。请查看堆栈跟踪了解更多信息   有关错误的信息以及它在代码中的起源。

     

异常详细信息:System.NullReferenceException:不是对象引用   设置为对象的实例。

     

来源错误:

     

执行期间生成了未处理的异常   当前的网络请求。有关的来源和位置的信息   可以使用下面的异常堆栈跟踪来识别异常。

     

堆栈追踪:

     

[NullReferenceException:对象引用未设置为的实例   对象。]
  StackExchange.Profiling.MiniProfilerHandler.GetSingleProfilerResult(HttpContext的   上下文)   C:\ TeamCity的\ buildAgent \工作\ 1de24adb938b932d \ StackExchange.Profiling \ MiniProfilerHandler.cs:292   StackExchange.Profiling.MiniProfilerHandler.ProcessRequest(HttpContext的   上下文)   C:\ TeamCity的\ buildAgent \工作\ 1de24adb938b932d \ StackExchange.Profiling \ MiniProfilerHandler.cs:93   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()   +912 System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean&amp; completedSynchronously)+164

1 个答案:

答案 0 :(得分:2)

确保显示MiniProfiler的网页在MiniProfiler.Settings.IgnoredPaths指定的网址中不包含被忽略的路径,默认情况下该网址包含/content//scripts//favicon.ico。网址为/content/Default.aspx的网页不会显示MiniProfiler,而/Pages/Default.aspx会显示该网页。

或者,从/content/移除MiniProfiler.Settings.IgnoredPaths

相关问题