web.config transforms for CAS integration

I have previously posted about using a different web.config file for each build configuration, to save you having to change your web.config each time you want to change from a development build to a production build etc (Read here).

That was some time ago though and MVC3 has since moved on to use web.config transforms, where you use XPath style commands to change the web.config file for each configuration.

As a useful reference here are the transforms I used for adding CAS integration into my app. You only need to change the attributes of the authentication node if you are not using forms authentication as your default. If you are using forms authentications as your default then you will probably need to use xdt:Transform=”RemoveAll” with the forms nodes, before you add the new one too.

More about web.config transforms is here.

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

  <configSections>
    <section name="casClientConfig"
           type="DotNetCasClient.Configuration.CasClientConfiguration, DotNetCasClient" xdt:Transform="Insert"  />
  </configSections>

  <casClientConfig
  casServerLoginUrl="https://login.casserver.com/cas/login"
  casServerUrlPrefix="https://login.casserver.com/cas/"
  serverName="http://myservername.com"
  notAuthorizedUrl="~/Security/NotAuthorised"
  cookiesRequiredUrl="~/Security/CookiesRequired"
  redirectAfterValidation="true"
  renew="false"
  singleSignOut="true"
  ticketValidatorName="Cas10"
  serviceTicketManager="CacheServiceTicketManager" xdt:Transform="InsertAfter(/configuration/configSections)" />


  <system.web>

    <authentication
       
        mode="Forms"
        xdt:Transform="SetAttributes">

      <forms
       loginUrl="https://login.casserver.com/cas/login"
       timeout="30"
       defaultUrl="/"
       cookieless="UseCookies"
       slidingExpiration="true"
       path="/MyVirtualPath" xdt:Transform="Insert" />
      
    </authentication>

    <httpModules>
      <add name="DotNetCasClient"
           type="DotNetCasClient.CasAuthenticationModule,DotNetCasClient" xdt:Transform="Insert" />
    </httpModules>
    
 
 
  </system.web>

  <system.webServer>
    <modules>
      <remove name="DotNetCasClient" xdt:Transform="Insert"/>

      <add name="DotNetCasClient"
           type="DotNetCasClient.CasAuthenticationModule,DotNetCasClient" xdt:Transform="Insert"/>
    </modules>
    
  </system.webServer>
</configuration>
Advertisements