Search code examples
asp.netglimpse

With Glimpse How To Turn It Off Without Disabling?


I love Glimpse but only when I' interested in what it has to tell me. I have a glimpse role that I can turn on and off to make glimpse go away (see code below) but what I really want is to be able to turn it on and off while it is enabled in my global.asax. I've tried going to site.com/glimpse.axd and set "turn glimpse off" but then on the next page refresh it is back.

What am I missing?

public class GlimpseSecurityPolicy : IRuntimePolicy
{
    public RuntimePolicy Execute(IRuntimePolicyContext policyContext)
    {
        var httpContext = policyContext.GetHttpContext();
        if (!httpContext.User.IsInRole("GlimpseUser"))
        {
            return RuntimePolicy.Off;
        }
        return RuntimePolicy.On;
    }

    public RuntimeEvent ExecuteOn
    {
        get { return RuntimeEvent.EndRequest; }
    }
}

In My Web.Config:

<glimpse defaultRuntimePolicy="On" endpointBaseUri="~/Glimpse.axd">
<runtimePolicies>
  <ignoredTypes>
    <add type="Glimpse.AspNet.Policy.LocalPolicy, Glimpse.AspNet" />
    <add type="Glimpse.Core.Policy.ControlCookiePolicy, Glimpse.Core" />
  </ignoredTypes>
</runtimePolicies>


Solution

  • Ok, the reason why clicking on the "Turn Glimpse Off" button has no effect is because the ControlCookiePolicy is disabled in the config, hence clicking that button will have no effect.

    So you need to remove that entry from the config to make that work again:

    <add type="Glimpse.Core.Policy.ControlCookiePolicy, Glimpse.Core" />
    

    when you are saying that

    The other code public class GlimpseSecurityPolicy" is in my global.asax

    you mean that the GlimpseSecurityPolicy is basically defined as an inner class of the Mvc Application class?

    Either way if you would enable logging for Glimpse in the config

    <glimpse defaultRuntimePolicy="On" endpointBaseUri="~/Glimpse.axd">
        <logging level="Trace" />
        <runtimePolicies>
        <ignoredTypes>
            <add type="Glimpse.AspNet.Policy.LocalPolicy, Glimpse.AspNet" />
        </ignoredTypes>
      </runtimePolicies>
    </glimpse>
    

    then you should see a glimpse.log file appear in the root of your web application, and once the application is started, you should see an entry like this:

    2014-06-13 09:48:25.8498 | DEBUG | Discovered IRuntimePolicy of type 'SOME NAMESPACE+GlimpseSecurityPolicy' and added it to collection. |

    If that is the case then the policy is actually discovered. You can put a breakpoint inside the Execute method to check whether a call is actually made and what the outcome is.