Could you please tell me how we will use more than 1 web.config file in asp.net?
You can use multiple web.config in different directories in the web application. This will help you to override any parent folder config settings
Multiple Web.Config files in ASP.NET web application
You can't use multiple web.config files as far as I know. You can however run create a new website that uses a different web.config file and has duplicate files.
If there is a particular setting you want to be variable, then your design sounds a bit inefficient and you should probably be handling those values outside the web.config file.
You can also split your config file into multiple parts, which is useful if it's hard to manage and want to modularise it. Do as follows:
Your Main.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings file="YourSettings.config" />
<system.web>
<!-- Continue as normal -->
</system.web>
</configuration>
Then create YourSettings.config
<!-- Referenced by Web.config -->
<appSettings>
<add key="Key" value="MyVal" />
</appSettings>
Related
We can configure the settings for the webpages in a particular folder by keeping single web.config. Can there be multiple web.config in a same hierarchy as i saw some where web.config.debug and web.config.release and web.config. Why they are intended for.
Those are web.config transformations, which allow you to apply changes to different builds of your project (debug, dev, release, etc).
The ones suffixed with .debug, .release, etc, are the transformation files. They take the base web.config and modify it using the XML-Document-Transform attributes you specify.
A classic use case is the debug=true attribute, which you never want to use in production. You can use a simple transformation to remove it in your web.config.release file:
Web.config
<configuration>
<compilation debug="true" />
</configuration>
Web.config.release
<configuration>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</configuration>
For my web application, I have several startup config values that need to be stored on a config xml file and will be loaded up when the web starts. My question is should I use an external xml or just put all those values into the web.config file? And if I use the external xml then when should I load it and where should I save the values to (Application_Start method? save to Application['name']?). And when I change this xml file, I need to restart the whole application right?
Thanks.
Without knowing more details, I say use the web.config. That is why we have it :)
When you edit web.config, the change will be picked up on the next request.
edit to address the comment
If your config file is getting bloated, you can move sections to an external file.
<configuration>
<appSettings configSource="appSettings.config" />
<connectionStrings configSource="connectionStrings.config" />
<system.web>
<pages configSource="pages.config" />
<httpHandlers configSource="httphandlers.config">
</system.web>
</configuration>
We are working on a web application that creates more web applications.
Each web application will have to get a Url Rewrite rule (URL REWRITE MODULE 2.0).
As far as I know, there's no way to add such rules without modifying the web.config file (am I right??).
So my plan was to work with multiple web.config partial files. One main .config file, and lots of .config files per application (every file will contain it's web application url rewrite rules).
This way sounds a little bit messy, but I can't think of anything else, and suggestions will be welcomed.
So is it possible to use very-multiple web.config files for the root application?
Thanks in advance, Gal.
This following Tag will do the trick.
The absence of this tag was the main reason for my problem when i using with two web.config files for my two different application running in my website.
**<location path="." inheritInChildApplications="false">**
<system.web>
<!-- ... -->
</system.web>
**</location>**
Every application must have a full web.config and not partial, exept if you go with net 4
The trick is to use a lot the remove command on the other inside web.config and remove the parents setting that must not used on this.
For example if on the main root you have the a module that you do not won to use it on the other trees, you use the remove command on all other web.config to remove it. Especial the modules that are on one Bin and not on an other directory bin.
<httpModules>
<remove name="TheHttoModuleNotNeedHere" />
<remove name="AnonymousIdentification" />
... add here your other modules for that directory...
</httpModules>
The remove command is working for almost all sessions on config.
You can do make it work, I have done it, but its a lot of work to find all the conflicts/unnecessary configs and remove it.
For some other session there also the clear command. For example on role Manager you can clear all and add new.
<roleManager enabled="true" ...>
<providers>
<clear />
<add name="MyName" ... type="System.Web.Security.SqlRoleProvider" />
</providers>
Hope this help as tips to make it work.
This should be a simple one. I am using a program that has themes defined in its Web.config file. I want to turn these off for a subdirectory.
I copied Web.config into a subdirectory and tried removing the theme attribute from the pages element on Web.config but that didn't get me anywhere. I got a bunch of errors about elements that are apparently not allowed in non-root Web.config files so I removed all of those elements, but I am still getting the same error.
I tried adding EnableTheming="False" in the ASPX Page header, the thing that defines Language=C#, etc., but it didn't work either.
So if someone can tell me a tested, confirmed way to make this work, I would appreciate that. I am using .NET Framework 2.0 on Server 2003.
Got it with a very basic Web.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<pages theme="" />
</system.web>
</configuration>
I want to know what best practice is for accessing settings
in config file when you have dev/test/production types.
If you have different config for each type when you
publish a ASP.NET website doesn't the config get copied as well??
Malcolm
We usually manually inject the settings file on each site. I think that it's uncommon, though not unheard of, to actually rely on VS to publish to your production site. Source control has dev/test/prod/ etc. web.config files.
ConfigurationManager.AppSettings ?
http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.appsettings.aspx
In Visual Studio 2010 you can maintain Multiple Web.Config and use a transformation to generate the correct Configuration for an environment.
http://blogs.msdn.com/webdevtools/archive/2009/05/04/web-deployment-web-config-transformation.aspx
Basically we can make have one default Web.Config and different Transformation files for each environment e.g.
Web.Debug.Config
Web.Staging.Config
Web.Production.Config
The Transformation file can override the value of a particular config item for the environment e.g.
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="personalDB"
connectionString="Server=StagingBox; Database=personal; User Id=admin; password=StagingPersonalPassword"
providerName="System.Data.SqlClient" xdt:Transform="Replace" xdt:Locator="Match(name)" />
<add name="professionalDB"
connectionString="Server=StagingBox; Database=professional; User Id=professional; password=StagingProfessionalPassword"
providerName="System.Data.SqlClient" xdt:Transform="Replace" xdt:Locator="Match(name)"/>
</connectionStrings>
</configuration>
Whenever we target build for that environment the Transformation are applied to the default Web.Config file.