I know I can set this in the web.config but I want to set it conditionally depending on environment and add it to our core library. I have tried the below code but it does not work.
HttpCookiesSection cookieSection = (HttpCookiesSection)ConfigurationManager.GetSection("system.web/httpCookies");
cookieSection.HttpOnlyCookies = true;
cookieSection.RequireSSL = true;
The error is:
System.Configuration.ConfigurationErrorsException
The configuration is read only.
This kind of approach works fine for app settings. Note: I am not wanting to save the web.config, just change the setting in memory.
It appears from the documentation that this property is get-set.
From the docs:
// Set the RequireSSL.
httpCookiesSection.RequireSSL = false;