itmanir
itmanir

Reputation: 177

How to set attributes in web.config only in release mode?

I want set this attribute only in release mode:

<system.web>
    <httpCookies domain=".mySite.com" />
  </system.web>

This is my Web.Release.Config:

<system.web>
<httpCookies name="someName" domain=".mySite.com"  xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
</system.web>

and this is my Web.Config:

<system.web>
        <httpCookies name="someName"/>
      </system.web>

But the httpCookies property not have name attribute!!! and get error that this attribute not valid.

Upvotes: 5

Views: 3857

Answers (2)

Carter Medlin
Carter Medlin

Reputation: 12465

If you just want to change one attribute without replacing the entire node, do this in your Web.Release.config.

  <system.web>
...
    <httpCookies xdt:Transform="SetAttributes(domain)" domain=".mySite.com" />

That will leave the rest of the httpCookies attributes alone, and only change domain. Make sure the new domain= appears after the xdt:Transform or it won't work.

Upvotes: 4

SteveChapman
SteveChapman

Reputation: 3081

This should work - add this to your Web.Release.config file:

<system.web>
    <httpCookies domain=".mySite.com" xdt:Transform="Replace" />
</system.web>

You don't need the name attribute (it doesn't exist anyway)

This will be the result in the transformed web.config:

<system.web>
    <httpCookies domain=".mySite.com" />
</system.web>

Note that the httpCookies element must be present in your Web.config file for the transform to work.

Upvotes: 10

Related Questions