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.
Related
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
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.
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.
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.