I am trying to add
<location inheritInChildApplications="false">
to my parent web application's web.config but it doesn't seem to be working.
My parent's web.config has:
<configuration>
<configSections>
</configSections>
// 10 or so custom config sections like log4net, hibernate,
<connectionStrings>
</connectionStrings>
<appSettings>
</appSettings>
<system.diagnostics>
</system.diagnostics>
<system.web>
<webParts>
</webParts>
<membership>
</membership>
<compilation>
</compilation>
</system.web>
<location ..>
<system.web>
</system.web>
</location>
<system.webServer>
</system.webServer>
My child web application is setup as an application in IIS, and is inheriting from the parent's web.config which is causing problems.
Where exactly should I place the
<location inheritInChildApplications="false">
so it ignores all the various web.config settings?
As the commenters for the previous answer mentioned, you cannot simply add the line...
<location path="." inheritInChildApplications="false">
...just below <configuration>. Instead, you need to wrap the individual web.config sections for which you want to disable inheritance. For example:
<!-- disable inheritance for the connectionStrings section -->
<location path="." inheritInChildApplications="false">
<connectionStrings>
</connectionStrings>
</location>
<!-- leave inheritance enabled for appSettings -->
<appSettings>
</appSettings>
<!-- disable inheritance for the system.web section -->
<location path="." inheritInChildApplications="false">
<system.web>
<webParts>
</webParts>
<membership>
</membership>
<compilation>
</compilation>
</system.web>
</location>
While <clear /> may work for some configuration sections, there are some that instead require a <remove name="..."> directive, and still others don't seem to support either. In these situations, it's probably appropriate to set inheritInChildApplications="false".
It needs to go directly under the root <configuration> node and you need to set a path like this:
<?xml version="1.0"?>
<configuration>
<location path="." inheritInChildApplications="false">
<!-- Stuff that shouldn't be inherited goes in here -->
</location>
</configuration>
A better way to handle configuration inheritance is to use a <clear/> in the child config wherever you don't want to inherit. So if you didn't want to inherit the parent config's connection strings you would do something like this:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<clear/>
<!-- Child config's connection strings -->
</connectionStrings>
</configuration>
I put everything into:
<location path="." inheritInChildApplications="false">
....
</location>
except: <configSections/>, <connectionStrings/> and <runtime/>.
There are some cases when we don't want to inherit some secions from <configSections />, but we can't put <section/> tag into <location/>, so we have to create a <secionGroup /> and put our unwanted sections into that group. Section groups can be later inserted into a location tag.
So we have to change this:
<configSections>
<section name="unwantedSection" />
</configSections>
Into:
<configSections>
<sectionGroup name="myNotInheritedSections">
<section name="unwantedSection" />
</sectionGroup>
</configSections>
<location path="." inheritInChildApplications="false">
<myNotInheritedSections>
<unwantedSection />
</myNotInheritedSections>
</location>
We were getting an error related to this after a recent release of code to one of our development environments. We have an application that is a child of another application. This relationship has been working fine for YEARS until yesterday.
The problem:
We were getting a yellow stack trace error due to duplicate keys being entered. This is because both the web.config for the child and parent applications had this key. But this existed for many years like this without change. Why all of sudden its an issue now?
The solution:
The reason this was never a problem is because the keys AND values were always the same. Yesterday we updated our SQL connection strings to include the Application Name in the connection string. This made the string unique and all of sudden started to fail.
Without doing any research on the exact reason for this, I have to assume that when the child application inherits the parents web.config values, it ignores identical key/value pairs.
We were able to solve it by wrapping the connection string like this
<location path="." inheritInChildApplications="false">
<connectionStrings>
<!-- Updated connection strings go here -->
</connectionStrings>
</location>
Edit: I forgot to mention that I added this in the PARENTS web.config. I didn't have to modify the child's web.config.
Thanks for everyones help on this, saved our butts.
If (as I understand) you're trying to completely block inheritance in the web config of your child application, I suggest you to avoid using the tag in web.config.
Instead create a new apppool and edit the applicationHost.config file (located in %WINDIR%\System32\inetsrv\Config and %WINDIR%\SysWOW64\inetsrv\config).
You just have to find the entry for your apppool and add the attribute enableConfigurationOverride="false" like in the following example:
<add name="MyAppPool" autoStart="true" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated" enableConfigurationOverride="false">
<processModel identityType="NetworkService" />
</add>
This will avoid configuration inheritance in the applications served by MyAppPool.
Matteo
This is microsoft's page on the location tag: http://msdn.microsoft.com/en-us/library/b6x6shw7%28v=vs.100%29.aspx
It may be helpful to some folks.
We're getting errors about duplicate configuration directives on the one of our apps.
After investigation it looks like it's because of this issue.
In brief, our root website is ASP.NET 3.5 (which is 2.0 with specific libraries added), and we have a subapplication that is ASP.NET 4.0.
web.config inheritance causes the ASP.NET 4.0 sub-application to inherit the web.config file of the parent ASP.NET 3.5 application.
However, the ASP.NET 4.0 application's global (or "root") web.config, which resides at C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config and C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config (depending on your bitness), already contains these config sections.
The ASP.NET 4.0 app then tries to merge together the root ASP.NET 4.0 web.config, and the parent web.config (the one for an ASP.NET 3.5 app), and runs into duplicates in the node.
The only solution I've been able to find is to remove the config sections from the parent web.config, and then either
Determine that you didn't need them in your root application, or if you do
Upgrade the parent app to ASP.NET 4.0 (so it gains access to the root web.config's configSections)
Related
I have a machine.config with this configuration:
<system.web>
<machineKey compatibilityMode="Framework20SP2" validationKey="123" decryptionKey="456" validation="SHA1" decryption="3DES"/>
And a web.config with this attribute
<system.web>
<machineKey decryption="SHA1"/>
Does the final configuration do a combination of both?
<machineKey compatibilityMode="Framework20SP2" validationKey="123" decryptionKey="456" validation="SHA1" decryption="SHA1"/>
or if I have redefined machineKey it will get overriden completely?
<machineKey decryption="SHA1"/>
Settings in child directory will either override or modify settings from parent directory. e.g. Lets take example of handlers or modules. In parent directory if web.config contains handlers like this.
<configuration>
<system.web>
<httpHandlers>
<add verb="*" path="SampleHandler.new" type="SampleHandler, SampleHandlerAssembly" />
</httpHandlers>
</system.web>
</configuration>
and if child directory contains handlers like this
<configuration>
<system.web>
<httpHandlers>
<add verb="*" path="*.SampleFileExtension" type="SampleHandler2 " />
</httpHandlers>
</system.web>
</configuration>
Then effective handlers available for child directory will be union of two configurations. So essentially configuration is getting modified here in child directory. If you add < clear/> tag right after < httpHandlers> tag in child directory's config file then it will override parent's configuration and only one handler which is there in child's config file will be available for child directory.
Now lets take second example. Consider configuration in question. In this case since we are re-declaring/configuring same setting in child's configuration file it will override parent's configuration settings and effective configuration will be whatever is there in child's configuration file. i.e.
<machineKey decryption="SHA1"/>
You may get more insight on how configuration works from this link.
http://weblogs.asp.net/jongalloway/10-things-asp-net-developers-should-know-about-web-config-inheritance-and-overrides
My application has this structure
MyApplication
-Themes
In my application's webconfig I remove the UrlAuthorization module and add my own:
<modules runAllManagedModulesForAllRequests="true">
<remove name="UrlAuthorization" />
<add name="MyModule" type="MyType, MyNamespace" preCondition="managedHandler" />
</modules>
My Theme folder has this webconfig (this is the complete webconfig):
<?xml version="1.0"?>
<configuration>
<system.web>
<pages styleSheetTheme="" validateRequest="false" />
</system.web>
</configuration>
I have this deployed in 3 environments. 2 of them works correctly but in one of them I have the UrlAuthorization module working when I make a request do a file inside the Theme folder.
I know that the UrlAuthorization is active because I do not get the resource I requested, but an URL /ReturnURl/... path
The < remove> tag is working because removing it causes the whole request to be redirect to the /ReturnUrl
Is there any reason that may cause this behavior to happen only in this machine?
I deployed all of them and I do not remember making and different task on any of them
thanks!
FYI, it was an issue due to the folders permissions in the file system. I made the environments identical and it worked.
I am trying to setup a custom session provider in my default / root web.config so that all of it's child sites are able to use it automatically.
Here's my configuration:
<configuration>
<system.web>
<sessionState mode="Custom" customProvider="RedisSessionStateProvider">
<providers>
<add name="RedisSessionStateProvider"
type="Harbour.RedisSessionStateStore.RedisSessionStateStoreProvider"
host="xxx.yyy.zzz" clientType="pooled" />
</providers>
</sessionState>
</system.web>
</configuration>
My issue is that the provider is dependent on a few assemblies, and I'm not sure of the proper way to reference them in my root web.config such that the child sites can use it.
I'd like to avoid using the GAC.
You can always put the assembly in the bin folder of the root website and then reference it in the web.config then use the add assembly tag.
See: http://www.daniweb.com/web-development/aspnet/threads/200904/add-assembly-to-root-web.config-in-asp.net
I'm training my web.config to recognize what the best default file is. According to my host it's supposed to look like in the listing below.
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<appSettings/>
<system.web>
<defaultDocument>
<files>
<clear />
<add value="Defalut.aspx" />
</files>
</defaultDocument>
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime/>
<pages controlRenderingCompatibilityVersion="4.0"/>
<machineKey/>
<customErrors defaultRedirect="Error.aspx" mode="On"/>
</system.web>
</configuration>
The problem is that VS2012 (Express) marks it blue and claims the error in the subject. First i thought that i could upload it as it is and by brute force make the server to like the file but it then got angry and spat out the following
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
As i read the error message it says that: "The configuration section 'defaultDocument' cannot be read because it is missing a section declaration."
I've done my homework and found the article below but due to the limitation in my situation (e.g. i need to manually upload the web.config file and i can't run any scripts on the server of my hosting company), it was to no avail.
How do i kill this little problem?
"Defalut.aspx" is a definite yellow flag.
SUGGESTION:
Just create a new dummy project with MSVS2012 (I don't have a copy handy, so I can't help you at the moment)
Cut and paste the auto-generated "web.config" into your project and verify that it works.
If it doesn't, make ONLY those MINIMAL changes needed to get a clean compile/execute.
Save a backup of your working web.config
Try adding your "defaultDocument" section and see what happens.
If it still doesn't work, please cut/paste:
a) the exact section (as I presume you did above)
b) the exact error message
ALSO:
Q: It now fails in BOTH your MSVS2012 (running locally) AND your target web server, correct?
Q: Are you sure the target web server is ASP.Net 4.0 capable?
You config looks correct but the error occurs because it cannot find the file that is mean to be the default document for all your website folders
So please replace "Defalut.aspx" with he correct spelling of the file in the below xml
<defaultDocument>
<files>
<clear />
<add value=*"Defalut.aspx"* />
</files>
</defaultDocument>
Late to the party, I know, but for anybody still with a similar problem, I don't believe this has anything to do with the spelling of the default page name (that will probably just give a 404 when it's accessed).
The real issue is that the defaultDocument section should actually be under system.webServer, not system.web. See defaultDocument Element for more info.
So your sample config file should look something like:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<appSettings/>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime/>
<pages controlRenderingCompatibilityVersion="4.0"/>
<machineKey/>
<customErrors defaultRedirect="Error.aspx" mode="On"/>
</system.web>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="Defalut.aspx" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
I've tried wrapping my
<system.web>
with
<location path="." InheritInChildApplications="false">
like this
<location path="." InheritInChildApplications="false">
<system.web>...</system.web>
</location>
But VS 2010 Web Developer Express keeps saying
The 'InheritInChildApplications' attribute is not allowed
When I run my web app there's an error:
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
Config Error Unrecognized attribute 'InheritInChildApplications'.
My configuration: ASP.NET 4.0 RTM, VS 2010, IIS 7.5
It could be because you don't have a namespace specified on the root node? eg
You need
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
not
<configuration>
I think the issue here is that inheritInChildApplications is not a valid attribute of the location node in .net 4.0.
The reason the above fix works is because you are specifically targeting the .net 2.0 configuration schema
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
.net 4.0 privdes a different way of dealing with config inheritance.
See http://msdn.microsoft.com/en-us/library/b6x6shw7.aspx and http://msdn.microsoft.com/en-us/library/ms178692.aspx for more details.
Shouldn't it be a lowercase 'i'?
<location path="." inheritInChildApplications="false">
I have been using it successfully on the last 4 or 5 projects I have worked on. My spec is similar to yours. I'm still using .NET 4 RC. I also include the system.webServer settings within location.
Good luck,
Rich
I use clear quite often to achieve this:
<configuration>
<system.web>
<assemblies>
<clear>
<clientTarget>
<clear>
<compilation>
<compilers>
<clear>
<httpHandlers>
<clear>
<httpModules>
<clear>
<serviceDescriptionFormatExtensionTypes>
<clear>
<webServices>
<protocols>
<clear>
<soapExtensionTypes>
<clear>
<soapExtensionReflectorTypes>
<clear>
<soapExtensionImporterTypes>
<clear>