3

I have installed Glimpse (Glimpse MVC4) and MiniProfiler (with EF support).

I also installed the MiniProfiler plugin for Glimpse.

I have that all wired up and working. I want to allow the configuration of Glimpse to determine if MiniProfiler should start profiling. That is, if Glimpse is enabled (through Glimpse.axd not via a config setting) I want to call MiniProfiler.Start() in the Application_BeginRequest() method. So, something like this:

protected void Application_BeginRequest()
{
    if (Glimpse.IsRunning)
    {
        MiniProfiler.Start();
    }
}

Is there a way to determine if Glimpse is enabled?

4

1 回答 1

5

从技术上讲,有一种方法,但我充其量称它为 hacky。我会让你决定它是否适合你的目的。

var policyString = HttpContext.Current.Items["__GlimpseRequestRuntimePermissions"].ToString();
RuntimePolicy glimpsePolicy;
RuntimePolicy.TryParse(policyString, out glimpsePolicy);

if (!glimpsePolicy.HasFlag(RuntimePolicy.Off))
{
    MiniProfiler.Start();
}

我称其为 hack 的原因是,虽然 Glimpse 可能On在请求的开始,但它可能会在稍后转为Off.

这种行为的一个例子是,一旦 ASP.NET 开始报告不受支持的媒体类型(如图像),Glimpse 就会自动关闭。ASP.NET 在 HTTP 处理程序运行之前无法知道媒体类型。在这种情况下,Glimpse 会说它在请求开始时打开,但在请求结束时会关闭。

于 2013-03-25T14:47:13.103 回答