Search code examples
asp.netsslhttpsweb-config-transformsecurityswitch

Unable to use web config transforms with securitySwitch. Possible workarounds?


I'm using securitySwitch for a few of my projects and it's worked wonderfully. However, one of my projects has grown and I'm unable to perform any web.config transforms on the securitySwitch config section.

So, in my web.config, I have the following:

<securitySwitch baseInsecureUri="uriWebsite1insecure" baseSecureUri="uriWebsite1secure" bypassSecurityWarning="true" mode="RemoteOnly" xmlns="http://SecuritySwitch-v4.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="SecuritySwitch-v4.xsd">
<paths>
  <add path="~/" ignoreCase="true" />
</paths>
</securitySwitch>

However, in one of my web.config transforms I need to change the baseInsecureUri and baseSecureUri to point to a different website:

<securitySwitch baseInsecureUri="uriWebsite2insecure" baseSecureUri="uriWebsite2secure" bypassSecurityWarning="true" mode="RemoteOnly"  xmlns="http://SecuritySwitch-v4.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="SecuritySwitch-v4.xsd" xdt:Transform="Replace">
<paths>
  <add path="~/" ignoreCase="true" />
</paths>
</securitySwitch>

It gives the following error: The http://schemas.microsoft.com/XML-Document-Transform:Transform attribute is not declared.

I'm looking for any possible solution, even if it's not a "clean" one.

Thank you for your time! - Andrew


Solution

  • Try removing the namespace declaration on the SecuritySwitch section. This should fix it.

    <securitySwitch baseInsecureUri="uriWebsite2insecure" baseSecureUri="uriWebsite2secure" bypassSecurityWarning="true" mode="RemoteOnly" xdt:Transform="Replace">
      <paths>
        <add path="~/" ignoreCase="true" />
      </paths>
    </securitySwitch>
    

    Also, if all you need to do is change those two attributes, you can try this instead:

    <securitySwitch baseInsecureUri="uriWebsite2insecure" baseSecureUri="uriWebsite2secure" xdt:Transform="SetAttributes" />