IIS 7 and Above
Configure the PS provider to use .NET 4.0 machine.config and root web...
Last post Mar 06, 2019 02:09 PM by SerkanG
Apr 21, 2011 03:47 AM|jberezanski|LINK
I'm having problems manipulating the configuration of .NET 4.0 applications under IIS 7.5.
It seems that despite the application being placed in an application pool configured to run under .NET 4.0, the configuration system reads machine.config and root web.config of .NET 2.0. This causes numerous errors ("section not declared") when we try to
configure settings that were introduced in 4.0 (or later installed as an extension to 4.0, e.g. AppFabric).
A simple example: let's assume the application "testapp" is installed under "Default Web Site" and configured to run in a 4.0 AppPool. The following valid web.config
<?xml version="1.0" encoding="UTF-8"?>
<add scheme="http" binding="myCustomHttpBinding" />
causes the following command to fail:
Get-WebConfiguration -filter '/system.serviceModel/protocolMapping' -pspath 'iis:\sites\Default Web Site\testapp'
The error message is:
The configuration section 'protocolMapping' cannot be read because it is missing a section declaration
The message is correct in a way, since this section is not declared in .NET 2.0. Now in the IIS MMC console it is possible to "Change .NET Framework version" which makes it possible to edit the root web.config. Is it possible to make a similar "switch" in
the Powershell provider?
I have found this blog post:
http://www.ksingla.net/2009/03/new_features_in_configuration_system_and_appcmd_in_iis-75/ which specifically states that IIS 7.5 configuration system can work against .NET 4.0 machine.config and root web.config and a new switch was added to appcmd to allow
Does the powershell provider support such a scenario?
Apr 25, 2011 03:36 AM|Lloydz|LINK
Do you mean you want to change the .net framework version of an application pool by using PowerShell? If it is the case, you can use the following command to fit your requirement. The command looks like:
Set-ItemProperty IIS:\AppPools\YourAppPoolName -name managedRuntimeVersion -value v4.0
Apr 27, 2011 06:48 AM|jberezanski|LINK
Thanks, but that's not the issue - as I wrote above, the application pool is already configured to run under .net 4.0.
I am encountering problems when trying to query and/or set configuration settings which were introduced in 4.0 (such as system.serviceModel/protocolMapping).
Apr 27, 2011 10:54 PM|Lloydz|LINK
It seems that the problem is caused by the section is not defined in IIS schema but machine.config. The command is used to get IIS configurations so any asp.net configuration sections that are defined in machine.config are considered as missing sections.
To solve this issue, you can redefine the section in your web.config(copy the defination from the machine.config). Then it will consider the section as one of your custom sections. For your case, the section looks like:
<sectionGroup name="system.serviceModel" type="System.ServiceModel.Configuration.ServiceModelSectionGroup, System.ServiceModel, Version=22.214.171.124, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="protocolMapping" type="System.ServiceModel.Configuration.ProtocolMappingSection, System.ServiceModel, Version=126.96.36.199, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
Hope this helps.
Apr 28, 2011 05:26 AM|jberezanski|LINK
The section is, in fact, defined in IIS schema (%systemroot%\system32\inetsrv\config\schema\ServiceModel_schema.xml):
<collection addElement="add" removeElement="remove" clearElement="clear" allowDuplicates="true">
<attribute name="scheme" type="string" required="true" isUniqueKey="true" validationType="nonEmptyString" validationParameter="" />
<attribute name="binding" type="string" required="true" validationType="nonEmptyString" validationParameter="" />
<attribute name="bindingConfiguration" type="string" />
Overall, the configuration is correct, because:
%systemroot%\inetsrv\appcmd list config "Default Web Site/testapp" -section:system.serviceModel/protocolMapping /clr:4
The only tool that fails is the Powershell provider.
Apr 28, 2011 09:40 PM|Lloydz|LINK
Yes. IIS Schema is extensible. Once you defined the schema with the content you posted, throw the file
to "%windir%\system32\inetsrv\config\schema" and register the section in applicationHost.config. Then the section could be seen via configuration editor in IIS manager.
Could you please take the following steps to see if this address the issue:
Open IIS Manager -> Select Server node -> Click "Change .NET Framework Version" at the right actions pane -> Switch to framework 4.0 then run the command in powershell again
May 02, 2011 11:44 AM|jberezanski|LINK
First, a correction. I chose the system.serviceModel/protocolMapping section to demonstrate the problem. It appears, however, that the IIS schema for this collection is not included in the .NET 4 installation package. The ServiceModel_schema.xml I mentioned
was in fact installed with Windows Server AppFabric. My problem can be reproduced on a clean .NET 4 system (no additional extensions) by querying e.g. the
system.web/fullTrustAssemblies collection, which has its schema defined in the NetFx40_IIS_schema_update.xml file.
To further clarify things: I'm not trying to define a custom configuration section, I'm just configuring an out-of-the-box .NET 4.0 feature.
I followed the steps you described, but I am still getting the same error in powershell. To be precise, I am able to modify the configuration (Add-WebConfiguration), but it is the
querying (Get-WebConfiguration) that causes errors.
Here are the complete minimal steps required to reproduce my problem:
Jul 17, 2014 02:56 AM|SzLaci|LINK
any update on this issue? I'm getting the same error (portocolMapping cannot be read...), when I want to read something from web.config. I am using IIS 7, with applicationPool set to v4.0. Also, tha same command on Server 2012 runs perfectly, only on WIndows
7 with IIS 7 I'm getting this strange error. What can be the problem?
Mar 06, 2019 02:09 PM|SerkanG|LINK
I got the exact problem, and I was trying to figure out what's wrong for 2 days. Possibly you may not need this information anymore but there may be some other people like me to have this problem. The solution for your problem is fixed by installing ".NET
Framework 3.5.1 Features" on the server, by doing this v4.0 machine.config will be inherited, so you'll stop getting "missing a section declaration" error for the section that already initialized at the machine.config.
I hope this would help some people.
Have a nice day