Asp.Net RequireSSL in Web.config

Viewed 8537

We have three different environments for our application such as Test,SIT and Prod. In Test we have HTTP and for remaining two we have HTTPS.

To set secure attribute for cookies, we have added below line of code in Web.config file. But in Test environment we do not need this code.

 <httpCookies requireSSL="true" />

Would like to have this code in SIT and Prod but not in Test. Is that possible to have this code in Web.config file for particular environment.

1 Answers

Yes you can use transformation to deal with the different environments. Assuming that you build the project for each environment.

Then add a new file web.Test.config that look something like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <system.web>
        <httpCookies requireSSL="false" xdt:Transform="Replace" />
    </system.web>
</configuration>

See https://bitwizards.com/Thought-Leadership/Blog/2014/November-2014/7-Steps-to-Setup-Web-Config-Transformations

Related