I'm trying to set up an IIS deployment step in my deploy process and I'm having trouble getting the right value to load into a web.config for a .netframework web app.
In my web config I have
<appsettings>
<add key="hostname" value=""/>
</appsettings>
My goal is for it to end up like this
<appsettings>
<add key="hostname" value="servername"/>
</appsettings>
I have the configuration variables feature turned on for the step, have enabled the "replace entries in .config files" option on, and imported a variable set that has a variable named "hostname" with a value of "servername"
I tried deploying it just as above but it didn't seem to do any transformation at all
I tried adding a project level variable named "hostname" with a value of "#{hostname}" but that gave me this result.
<appsettings>
<add key="hostname" value="#{hostname}"/>
</appsettings>
The second one tells me that it recognizes the project level variable but it isn't recognizing the value as a variable. Is there something I'm missing to get it to recognize the #{hostname} value as a variable set variable?
There are two items I can think of to check.
The first one is to verify that the library variable set is actually included in the project. It sounds like it might not be based on the behavior.
The second one is not to use the same name for the project and library variables. Having both named "hostname" means that one overwrites the other. Along with that, having a variable named "hostname" with a value of "#{hostname}" creates a loop and could be why you're seeing it replaced strangely.
Best,
Ryan
Related
First of all
I want to separate my web.config file and any sensitive data by separating into 2 different files.
Something like
web.config
sensitiveData.config
Moreover
I need to this to be configuration dependent. This can be implemented by xml-transform. But I don't know how to make web.config parametrised and configuration dependent.
How I tried
My idea is to add keys into appSettings and use in web.config, additionally here is a property appSettings.File where can be stored file with params and in xml-transformations I can simply change file to change configuration.
Well, I know about appSettings, I have added some
</appSettings>
<add key="MyConnstring" value="connstring" />
</appSettings>
But it is a mistake, because this can't be done, this is incorrect
<connectionStrings>
<add name="sqlwork" providerName="Oracle.DataAccess.Client" connectionString=MyConnstring />
</connectionStrings>
To summarise
Is there any ideas how it can be done to perform.
Sensitive data in a separate file
Configuration dependent sensitive data
its possible to move connection strings and other sensitive data in appsettings.
<configuration...
<appSettings configSource="config/appSettings.config"/>
<connectionStrings configSource="config/connections.config"/>
....
Here, appSettings.config in config folder contains sensitive app settings and connections.config contains the connection strings.
Reference: How can I simplify my Web.config file?
You can still read the settings and connection strings using ConfigurationManager.
We're trying to leverage Azures deployment slots for an Umbraco site we've built.
By default Umbraco uses a DSN defined in the connectionStrings sections of the web.config and we want it to use the connection string for the deployment slot it's sitting in.
What we've tried
Azure deployment slots put all defined app settings (and connection strings) into environment variables and to access them we can use Environment.GetEnvironmentVariable() which works but there doesn't seem to be a way to tell Umbraco to do this.
So in OnApplicationInitialized() (in /App_Code/Core/UmbracoAppStart.cs) we loaded the connectionstring section from the web.config, grabbed the connstr from env vars, added the DSN to the connectionstring section and saved.
The correct connection string is grabbed and stored but this seems to recycle the app (due to a web.config change) and thus we just get timeouts. (Or Umbraco XML cache errors, or it takes 20 mins to load the page).
I know you can store the appsettings and connectionstrings sections in separate files. But the file attribute (that doesn't cause a recycle if the referenced file is changed) doesn't work on the connectionStrings section - only the configSource attribute and that DOES recycle if changed.
(from: ASP.NET web.config: configSource vs. file attributes)
Help
Has anyone found a way around this?
We simply need to get Umbraco to use the deployment slot connection string - not the one in webconfig.
I'm even willing to copy and paste blindly at the moment without understanding how it works - and I hate doing that :). But that's what happens when people agree when the client wants to go live just before Christmas...
You don't need to do any code to use Azure connection string or the app settings. Just give them the same keys/names as you have on your web.config and they will be used instead.
So if you have this on your web config:
<add name="umbracoDbDSN" connectionString="Server={server};Initial Catalog={db};Persist Security Info=False;User ID={user};Password={password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=300;" providerName="System.Data.SqlClient" />
Your slot configuration should be this:
To replace an app setting just use the same key. So for this:
<add key="umbracoUseSSL" value="false" />
You'd use this:
If you want the setting to be slot specific you have to activate the Slot setting checkbox.
I integrated active directory with sitecore and it works perfect, now i am trying to write patches for the config changes. Sections <membership defaultProvider="sitecore" hashAlgorithmType="SHA1"> and <roleManager defaultProvider="sitecore" enabled="true"> are changed for connection setting to AD. When i try to write config patch for this section, this section is not built at run time. But the domains section works, i mean the patch i created for this section works and writes to web.config at runtime. I observed a difference here Domains section is under <Sitecore>, <membership> and <roleManager > are in <system.web> section. Is this the reason that these are not included in web.config? can we write patches for those sections only under <sitecore>?
Any ideas are appreciated.
Thanks.
You can only patch elements within the /configuration/sitecore element.
Refer this post:
http://www.sitecore.net/Learn/Blogs/Technical-Blogs/John-West-Sitecore-Blog/Posts/2011/05/All-About-Web-config-Include-Files-with-the-Sitecore-ASPNET-CMS.aspx
I think you have to use config transforms as mentioned by leandro.
I assumming you are using Visual Studio ¿? You must specify in what are you working.
If so, you need create a transform file for the build configuration that you need, for example, one config for every environment or publish type.
Try a look at this:
http://msdn.microsoft.com/en-us/library/vstudio/dd465318%28v=vs.100%29.aspx
I don't know what I'm doing wrong, but I almost feel I've tried everything. I can't seem to get the web.config of my project to transform with my web.debug.config changes. I read someplace that transformation only takes place when being published. Then I read that SlowCheetah could handle this, so I installed it into my project. It doesn't make any difference either.
Running VS 2012 Express. I debug using the IIS Express local server that was installed by VS. I run Firefox as my browser.
web.config:
<appSettings>
<add key="SiteUrl" value="http://development.mysite.com/" />
</appSettings>
web.debug.config:
<appSettings>
<add key="SiteUrl" value="http://localhost:4652/"
xdt:Transform="SetAttributes"
xdt:Locator="Match(key)" />
</appSettings>
I've also tried using Replace:
<appSettings>
<add key="SiteUrl" value="http://localhost:4652/"
xdt:Transform="Replace"
xdt:Locator="Match(key)" />
</appSettings>
When running in Debug configuration locally:
string siteurl = ConfigurationManager.AppSettings["SiteUrl"];
Still results in siteurl being http://development.mysite.com/
I've ran Preview Transform by right clicking on the web.debug.config and it shows the transform being made perfectly, but not when I run the web application locally.
Have to admit, I don't see how to configure SlowCheetah. I don't see any way to configure it and I've been thinking maybe it does "something" on its own. :S
Does anyone know how to overcome this or if I might be doing something wrong?
I'd suggest ignoring slow cheetah for the moment because I don't think you need it. I've used it for Windows Forms development, but haven't had a need for web development. Instead use the standard one click web deploy mechanism, and rethink how you use config transforms.
Basically, only utilize transforms when you are publishing, and put your local development settings in your main Web.config instead of a transform.
Then if you have a lab/test/sandbox environment you want to publish to create a solution and project configuration for that environment.
Next right click on the Web.config and click Add Config Transform to add a config transform for the solution configuration you just created.
Let's say you added a "Sandbox" solution configuration. If that's the case then a new file named Web.Sandbox.config will appear in Solution Explorer. Go ahead and update the values in Web.config and Web.Sandbox.config like so.
Web.config:
<appSettings>
<add key="SiteUrl" value="http://localhost:4652/" />
</appSettings>
Web.Sandbox.config:
<appSettings>
<add key="SiteUrl" value="http://sandbox.mysite.com/"
xdt:Transform="SetAttributes"
xdt:Locator="Match(key)" />
</appSettings>
Finally, you need to make a "sandbox.mysite.com" (or whatever your URL really is) publish profile and make sure that its Configuration is Sandbox so that the Web.Sandbox.config transform is used during publish.
I finally have TeamCity setup to build on Source Control changes, and a separate MSBuild task setup to package and deploy to IIS on the staging server using the 'package' target and the generated 'deploy.cmd' script. Everything is perfect in terms of build events, file inclusion/exclusion, etc...
However, I've come across a problem with how the package is being deployed. Whenever I deploy the package to the server, the IIS settings get blown away. For example, I can set cache expiration headers or turn on static compression, and after I deploy my package they will revert to the default values of the server.
Does anyone know how I can get around this? Is there a parameter I can pass or rule I can ignore?
I think what you are running into is different from what you might think.
In IIS 7 when you set the values for properties like you are describing the configuration for that is stored in the web.config for the application, and not applicationHost.config. For example I just created a site and modified those settings, then inside my web.config file the following fragment was dropped in.
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<urlCompression doStaticCompression="false" />
<caching>
<profiles>
<add extension=".aspx" policy="CacheUntilChange" kernelCachePolicy="DontCache" />
</profiles>
</caching>
</system.webServer>
So what is happening when you perform a sync the web.config in your package is overwriting the web.config which has the modified properties in it. What you need to do to configure your application in IIS 7 as you want it, then grab the node from place it in your web.config file. Alternatively if you want you can place it in either web.debug.config or web.release.config if you want to only have that in your web.config when publishing.