2

I am interested in being able to turn Glimpse off completely in the lightest weight way that I can manage. Between the glimpse documentat and the response to this question How to disable Glimpse, the difference between turning Glimpse.axd off and defaultRuntimePolicy="Off" the strongest "off" functionality I can see is setting the defaultRuntimePolicy to off in the web.config file.

However, this still loads a number of glimpse assemblies into my process as shown in the debugger - the answer to this question Why is Glimpse still running? sheds some light on why.

So what I've been doing is keeping around a GlimpseOff shelveset that comments out the glimpse configuration in my web.config file and also comments out the references in my .csproj file. And applying it when I really need glimpse turned off. This works, and I'm pretty sure it really does turn everything off fully, but it is pretty cumbersome.

The alternatives I've considered are (a) removing the glimpse nuget pacakges when I need to turn it off, which is even more cumbersome than my current solution or (b) creating a new build configuration in visual studio which doesn't include the glimpse modules and preforms a web.config transform to remove the configuration.

Neither of these seem optimal. Anyone have a better/cleaner/easier way to do this?

Community
  • 1
  • 1
David W Gray
  • 681
  • 6
  • 18

1 Answers1

4

You could use an XML transform to remove the Glimpse entries in Release mode/production.

Adding these entries to web.release.config:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">

  <configSections>
    <section name="glimpse" xdt:Transform="Remove" />
  </configSections>

  <glimpse xdt:Transform="Remove"/>

  <system.web>
    <httpModules>
      <add name="Glimpse" xdt:Transform="Remove"/>
    </httpModules>
    <httpHandlers>
      <add path="glimpse.axd" xdt:Transform="Remove" />
    </httpHandlers>
  </system.web>

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <add name="Glimpse" xdt:Transform="Remove" />
    </modules>
    <handlers>
      <add name="Glimpse" xdt:Transform="Remove" />
    </handlers>
  </system.webServer>

</configuration>

If you'd like, you can input this transform and your web.config into the Web Config Transform Tester to make sure it works for your app.

nikmd23
  • 9,095
  • 4
  • 42
  • 57
  • Nik, this is a lighter weight version of what I was considering for (b), and is probably most of the solution for someone who wants to have glimpse turned off completely when they deploy to production. But I checked and with this solution the glimpse assemblies are still loaded even if their not accessible. My solution to this is probably to put conditionals in my .csproj file, any other thoughts on that? – David W Gray Feb 25 '15 at 17:56
  • Also, my particular case is that I would like to turn glimpse off on my local machine, web.config transforms happen at publishe time -http://stackoverflow.com/questions/3613714/make-web-config-transformations-working-locally - any thought on alternatives to that part of the solution? – David W Gray Feb 25 '15 at 18:15