MSDeploy over-writing IIS settings - visual-studio

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.

Related

How to make web.config parametrized in asp.net

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.

Umbraco, Azure deployment slots and Connection Strings

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.

generate web.config at run time - sitecore

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

web.debug.config Transform not working

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.

Nuget packages to add their settings in custom xml file instead of the web/app config file

With some custom logic I have added a template for my web config in my Asp Mvc 4 application. When I need to modify the web.config file I am editing the template file for it and the changes are replaced in the web config file when I run the application. The problem is that when I add a package via nuget which needs to modify the web config file I am losing those settings as everything is overriden from my template file. Is there a way to somehow force the nuget packages to modify some custom xml file instead of the original web config file. For example, to modify mytemplate.xml instead of web.config.xml.
I am very new in this area and couldn't find a solution for my problem. As far as I understand packages that need to modify the web.config file come with web.config.transform file that merges the required fields and my only solutions is to manually replace the settings added to my web config file by the package into the template file. Is there another solution ? Thanks!
You are using your web.config file to do two different things:
Static configuration for nuget packages
Dynamic configuration for your site
web.config files allow you to define some of your settings in an external file and import them - e.g.
<configuration>
...
<appSettings configSource="appSettings.config" />
...
</configuration>
This is appSettings.config:
<appSettings>
<add key="umbracoDbDSN" value="..."/>
<add key="DefaultInstanceName" value="..."/>
<add key="aspnet:MaxHttpCollectionKeys" value="..."/>
</appSettings>
It's unlikely that you need to completely re-generate your web.config every build, probably only specific sections - if these don't clash with your installed packages then this approach would give you the flexibility your application needs.
OR PLAN B
packages.config lists all of the active packages in your solution
Packages store their web.config settings in a local file:
/packages/package/content/Web.config.transform
Can you extend the process that builds your web.config file to:
Enumerate the active packages
Check for a content/Web.config.transform file
Merge those files into your web.config build pipeline
I can't see any way of re-configuring nuget to push the configuration into a different file.

Resources