![](/img/trans.png)
[英]Can I use MiniProfiler to instrument an ASP.NET MVC WebApi website?
[英]Can't get MVC MiniProfiler to show on ASP.net website
我的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
則會拋出錯誤:
你調用的對象是空的。
描述:執行當前Web請求期間發生未處理的異常。 請查看堆棧跟蹤以獲取有關錯誤及其源自代碼的位置的更多信息。
異常詳細信息:System.NullReferenceException:未將對象引用設置為對象的實例。
來源錯誤:
在執行當前Web請求期間生成了未處理的異常。 可以使用下面的異常堆棧跟蹤來識別有關異常的起源和位置的信息。
堆棧跟蹤:
[NullReferenceException:對象引用未設置為對象的實例。]
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
確保顯示MiniProfiler網頁中不包含由指定的URL忽略的路徑MiniProfiler.Settings.IgnoredPaths
,默認情況下有/content/
, /scripts/
和/favicon.ico
。 帶有URL /content/Default.aspx
頁面不會顯示/Pages/Default.aspx
,而/Pages/Default.aspx
會顯示它。
或者,從MiniProfiler.Settings.IgnoredPaths
刪除/content/
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.