Question

I have an xml file, saml.config that contains some saml info. That information needs to get transformed in release builds to include production urls instead of development and staging urls. In my development and staging environments the transformation happens perfectly, in the release environment, the transformation does not take.

I have been trying out the http://webconfigtransformationtester.apphb.com/ to test out the transforms, and they are not being applied, but again, VS applies them perfectly.

The base saml.config file:

<?xml version="1.0"?>
<SAMLConfiguration xmlns="urn:componentspace:SAML:2.0:configuration">
    <ServiceProvider Name="Portal.Web" AssertionConsumerServiceUrl="http://localhost:49462/SingleSignOn/ConsumeAssertion"/>
    <PartnerIdentityProvider Name="MTMIdentity"
                             SignAuthnRequest="false"
                             WantResponseSigned="false"
                             WantAssertionSigned="false"
                             WantAssertionEncrypted="false"
                             SingleSignOnServiceUrl="https://identity.*********.com/SingleSignOn/"/>
</SAMLConfiguration>

The transform file:

<?xml version="1.0" encoding="utf-8" ?>
<SAMLConfiguration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xmlns="urn:componentspace:SAML:2.0:configuration">
  <ServiceProvider Name="Portal.Web" AssertionConsumerServiceUrl="https://***********.com/SingleSignOn/ConsumeAssertion" xdt:Transform="SetAttributes" xdt:Locator="Match(Name)" />
</SAMLConfiguration>

The result should replace the localhost url in the service provider AssertionConsumerServiceUrl with the ***********.com version, but it does not

<?xml version="1.0"?>
<SAMLConfiguration xmlns="urn:componentspace:SAML:2.0:configuration">
    <ServiceProvider Name="Portal.Web" AssertionConsumerServiceUrl="http://localhost:49462/SingleSignOn/ConsumeAssertion" />
    <PartnerIdentityProvider Name="MTMIdentity" SignAuthnRequest="false" WantResponseSigned="false" WantAssertionSigned="false" WantAssertionEncrypted="false" SingleSignOnServiceUrl="https://identity.********.com/SingleSignOn/" />
</SAMLConfiguration>

Why is the transform tester not applying the transformation?

EDIT:

I should add that I use the SlowCheetah addin / nuget package to handle the transformation locally and in our staging environment.

Considering the documentation (http://support.appharbor.com/kb/getting-started/managing-environments) states

Configuration file transformation is supported on all .config files that have a corresponding .release.config file.

I assume that AppHarbor can do this without SlowCheetah. But again, the WebConfigTransformTester tool does not apply this transformation.

So the question is still, how can I apply this transformation? Can I use SlowCheetah in AppHarbor?

EDIT:

Upon further investigation, it appears that AppHarbor is NOT applying the transformations to the Web.Config as well.

My Configs:

enter image description here

AppSettings in Web.Config

<appSettings>
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="aspnet:UseHostHeaderForRequestUrl" value="true" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="Environment" value="Development" />
</appSettings>

Notice the Environment is set to "Development"

The release transformation:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <appSettings>
        <add key="Environment" value="Release" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
    </appSettings>
    <system.web>
        <compilation xdt:Transform="RemoveAttributes(debug)" />
        <customErrors defaultRedirect="GenericError.htm" mode="Off" xdt:Transform="Replace">
            <error statusCode="500" redirect="InternalError.htm"/>
        </customErrors>
    </system.web>
</configuration>

Notice the Environment is being replaced with "Release"

The AppHarbor Environment:

enter image description here

After the deploy to AppHarbor, I downloaded the build and checked the Web.Config and it still has the Environment setting at "Development".

EDIT:

I added an Action to one of my Controllers that reads the Environment AppSetting and outputs to the view, and much to my surprise it was "Release"!!!

So what gives? The "Download Build" content does not have the transformation in place, but when a request happens it does? When does AppHarbor apply the transformation? Is it at runtime instead of during the build?

EDIT:

Heard back from the AppHarbor guys and the transformation happens on the actual publish, so even though the build has a "Published Websites" folder, it is still not the final output of the publish actions.

Thanks, Joe

Was it helpful?

Solution

We have just rolled out the solution (using the newest transformation assemblies as you point out) for this issue and updated http://webconfigtransformationtester.apphb.com/ accordingly. Your transformations should be applied as expected now.

Thank you for your thorough investigation of this issue.

OTHER TIPS

Come to find out, the answer to my original question as to way the transformation is not taking place, is because the xmlns attribute in the root node of the config file.

Unfortunately, the http://webconfigtransformationtester.apphb.com/ does not give you any kind of information about why the transformation did not take place, but if you look through the code, you can see that there is a logger available, but it is being set to null.

I ended up pulling the code and adding a logger and found a warning "No element in the source document matches '/SAMLConfiguration'". Digging a bit further I found this post Why does this web.config transform say it can't find the applicationSettings element? that in Sayed's answer he states that older MSBuild Transformation Tasks do not honor the xmlns attribute.

Removing the xmlns attribute from both the config file and the transform file should solve the problem.

However, in my case the xmlns attribute is required and cannot be removed.

So until AppHarbor updates their transformation assemblies to use the MSBuild v11.0 assemblies, I am pretty much stuck.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top