Sitecore.Glimpse icon indicating copy to clipboard operation
Sitecore.Glimpse copied to clipboard

install.xdt does not support <location> node in web.config

Open owenmartin opened this issue 11 years ago • 6 comments

Trying to install nuget package causes an error to be thrown as our web.config contains the node around <system.webServer>

Example web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <modules>
        <add name="Glimpse" type="Glimpse.AspNet.HttpModule, Glimpse.AspNet" preCondition="integratedMode" />
      </modules>
      <handlers>
        <add name="Glimpse" path="glimpse.axd" verb="GET" type="Glimpse.AspNet.HttpHandler, Glimpse.AspNet" preCondition="integratedMode" />
      </handlers>
</configuration>

Given that /configuration/system.webServer does not exist, the transformation fails.

owenmartin avatar Sep 17 '13 09:09 owenmartin

Can you email me your web.config (use my gmail a/c)?

kevinobee avatar Sep 17 '13 09:09 kevinobee

With the information that the location element starts after the <configSections> element and ends before the <runtime> element I have been able to recreate the issue.

PM> install-package sitecore.glimpse
Attempting to resolve dependency 'Glimpse (≥ 1.6.1)'.
Attempting to resolve dependency 'Glimpse.AspNet (≥ 1.4.1)'.
Installing 'Glimpse 1.6.1'.
Successfully installed 'Glimpse 1.6.1'.
Installing 'Glimpse.AspNet 1.4.1'.
Successfully installed 'Glimpse.AspNet 1.4.1'.
Installing 'Sitecore.Glimpse 0.3.0'.
Successfully installed 'Sitecore.Glimpse 0.3.0'.
Adding 'Glimpse 1.6.1' to Website.
Successfully added 'Glimpse 1.6.1' to Website.
Adding 'Glimpse.AspNet 1.4.1' to Website.
Successfully added 'Glimpse.AspNet 1.4.1' to Website.
Adding 'Sitecore.Glimpse 0.3.0' to Website.
Uninstalling 'Sitecore.Glimpse 0.3.0'.
Successfully uninstalled 'Sitecore.Glimpse 0.3.0'.
Uninstalling 'Glimpse.AspNet 1.4.1'.
Successfully uninstalled 'Glimpse.AspNet 1.4.1'.
Uninstalling 'Glimpse 1.6.1'.
Successfully uninstalled 'Glimpse 1.6.1'.
Install failed. Rolling back...
install-package : An error occurred while applying transformation to 'web.config' in project 'Website': No element in the source document matches 
'/configuration/system.webServer/modules/add[@name='SitecoreRewriteModule']'
At line:1 char:1
+ install-package sitecore.glimpse
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], InvalidDataException
    + FullyQualifiedErrorId :     NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand

kevinobee avatar Sep 18 '13 17:09 kevinobee

The <location> element looks to be breaking the install-package glimpse.aspnet step.

Specifically you end up with a web.config that ends with:

<glimpse defaultRuntimePolicy="On" endpointBaseUri="~/Glimpse.axd">
  <!-- If you are having issues with Glimpse, please include this. It will help us figure out whats going on. 
  <logging level="Trace" />-->

  <!-- Want to use Glimpse on a remote server? Ignore the LocalPolicy by removing this comment.
  <runtimePolicies>
    <ignoredTypes>
      <add type="Glimpse.AspNet.Policy.LocalPolicy, Glimpse.AspNet"/>
    </ignoredTypes>
  </runtimePolicies>-->
</glimpse><system.web>
    <!-- Glimpse: This can be commented in to add additional data to the Trace tab when using WebForms
    <trace writeToDiagnosticsTrace="true" enabled="true" pageOutput="false"/> -->
    <httpModules>
        <add name="Glimpse" type="Glimpse.AspNet.HttpModule, Glimpse.AspNet" />
    </httpModules>
    <httpHandlers>
        <add path="glimpse.axd" verb="GET" type="Glimpse.AspNet.HttpHandler, Glimpse.AspNet" />
    </httpHandlers>
</system.web><system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules>
        <add name="Glimpse" type="Glimpse.AspNet.HttpModule, Glimpse.AspNet" preCondition="integratedMode" />
    </modules>
    <handlers>
        <add name="Glimpse" path="glimpse.axd" verb="GET" type="Glimpse.AspNet.HttpHandler, Glimpse.AspNet" preCondition="integratedMode" />
    </handlers>
</system.webServer></configuration>

and attempts to the browse the site generate HTTP 500 responses.

image

kevinobee avatar Sep 18 '13 19:09 kevinobee

Just to clarify, if you run install-package glimpse.aspnet the package installs without any warnings in the package manager console but the web site will return HTTP 500 errors as the web.config will now contain multiple definitions for the <system.web> and <system.webServer> elements.

kevinobee avatar Sep 18 '13 19:09 kevinobee

Indeed, manual intervention is required. I believe this is because Glimpse using a .transform, rather than a .xdt, and so the default behaviour is to insert missing nodes where applicable, whereas xdt just goes bang, and the InsertIfMissing attribute doesn't seem to work as nicely as it should

owenmartin avatar Sep 18 '13 19:09 owenmartin

Now that NuGet finally supports .xdt based transforms, we'll be looking at switching over to those. We get issues reported from time to time stating that NuGet does the wrong thing to people's web.config, so hopefully we can clean those up.

@kevinobee - please feel free to open an issue in the Glimpse issue tracker and we will try to clean this up ASAP. I'm not 100% sure though that even .xdt transforms would alleviate this problem.

nikmd23 avatar Sep 18 '13 20:09 nikmd23