简体   繁体   English

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

[英]Can't get MVC MiniProfiler to show on ASP.net website

My web.config file: 我的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>

My global.asax: 我的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? 任何想法为什么MiniProfiler没有显示任何东西?

Update 更新

If I visit https://127.0.0.1:3333/mini-profiler-resources/includes.js in my browser, it's returning the JS file! 如果我在浏览器中访问https://127.0.0.1:3333/mini-profiler-resources/includes.js ,它将返回JS文件! It's just not rendering the includes on the page itself. 它只是不在页面本身上呈现包含。

If I visit /mini-profiler-resources/results it throws the error: 如果我访问/mini-profiler-resources/results则会抛出错误:

Object reference not set to an instance of an object. 你调用的对象是空的。

Description: An unhandled exception occurred during the execution of the current web request. 描述:执行当前Web请求期间发生未处理的异常。 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. 异常详细信息:System.NullReferenceException:未将对象引用设置为对象的实例。

Source Error: 来源错误:

An unhandled exception was generated during the execution of the current web request. 在执行当前Web请求期间生成了未处理的异常。 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.] [NullReferenceException:对象引用未设置为对象的实例。]
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 C:\\ TeamCity \\ buildAgent中的StackExchange.Profiling.MiniProfilerHandler.GetSingleProfilerResult(HttpContext context)位于c:\\ TeamCity \\ buildAgent \\ work \\ 1de24adb938b932d \\ StackExchange.Profiling \\ MiniProfilerHandler.cs:292 StackExchange.Profiling.MiniProfilerHandler.ProcessRequest(HttpContext context) \\ 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

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 . 确保显示MiniProfiler网页中不包含由指定的URL忽略的路径MiniProfiler.Settings.IgnoredPaths ,默认情况下有/content//scripts//favicon.ico A page with the URL /content/Default.aspx won't show the MiniProfiler, whereas /Pages/Default.aspx will show it. 带有URL /content/Default.aspx页面不会显示/Pages/Default.aspx ,而/Pages/Default.aspx会显示它。

Alternatively, remove /content/ from MiniProfiler.Settings.IgnoredPaths . 或者,从MiniProfiler.Settings.IgnoredPaths删除/content/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM