0

I have this block in my web.config:

<rewrite>
  <rules>
    <rule name="Remove Trailing Slash" stopProcessing="false">
      <match url="(.*)/$" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
      </conditions>
      <action type="Rewrite" url="{R:1}" />
    </rule>
    <rule name="Angular UI Router - HTML5 Mode" stopProcessing="true">
      <match url=".*" />
      <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{URL}" pattern="/api/" negate="true" />
      </conditions>
      <action type="Rewrite" url="/app/" />
    </rule>
  </rules>
</rewrite>

In an Azure release pipeline I'm using the MagicChunks tool to transform the web.config to change the second action elements' url attribute to "/" but it is failing. The transform I have is:

{
  "rewrite/rules/rule/action[@type='Rewrite' and @url='/app/']/@url": "/"
}

The error it throws up is:

System.ArgumentException:***There***is***empty***items***in***the***path.

How can I target an attribute to be transformed when it is not the attribute(s) being used as the target path?

Matt W
  • 11,753
  • 25
  • 118
  • 215
  • When I tested the extension on my side, it throw a warning `[warning]Task 'MagicChunks' (2.0.3) is using deprecated task execution handler.` though it worked well to transform the web.config. Maybe this extension needs some update to meet latest devops extension rule... – LoLance Apr 02 '20 at 10:32

1 Answers1

0

Not sure how your web.config looks like, but there's something wrong with your transform syntax. Check document from that extension. You should use something like:

{
  "rewrite/rules/rule[@name='Angular UI Router - HTML5 Mode']/action[@type='Rewrite']/@url": "/"
}

Since I tested your script in this way:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
  </system.web>
  <rewrite>
    ...
  </rewrite>
</configuration>

So I actually used something like:

{
  "configuration/rewrite/rules/rule[@name='Angular UI Router - HTML5 Mode']/action[@type='Rewrite']/@url": "/"
}

Be careful about the root node in your web.config. Then it should work well to replace the url attribute to "/". Let me know if I misunderstand anything :)

LoLance
  • 25,666
  • 1
  • 39
  • 73