We automate the collection and configuration of the IIS server using Powershell on Windows Server 2012 / IIS8.
Scripts create websites, application pools, set permissions, bind certificates, etc. Scripts are run from an XML file containing detailed information about all websites. The scripts configure everything you need to run websites, except for the content, which is then simply copied to the appropriate directory.
Everything works fine as long as there is no content in the directory (only for the default HTML page for testing).
If we copy applications to the directory and try to additionally configure sites using Powershell, applications using .NET 2 and 3.5 will display the following error:
Error: There is a duplicate section 'system.web.extensions / scripting / scriptResourceHandler' defined by
+ CategoryInfo : NotSpecified: (:) [Set-WebConfiguration], COMException + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.IIs.PowerShell.Provider.SetConfigurationCommand + PSComputerName : xxxxxxxxxxx
I carefully studied this topic and it seems that the problem is that System.Web.Extensions was moved to the machine.config file for .NET 4.0 applications, which means that if the section specified again in the web.config file is a duplicate, This makes sense, except that the applications that are bugs are .NET 2.0 or 3.5 applications that use the application pool installed as .NET 2.0.
I believe that the problem is that Powershell itself (in Windows Server 2012) works with CLR 4.0, and therefore, when changing the IIS configuration, it needs to analyze the configuration files hierarchically (from machine.config to web.config). He believes that System.Web.Extensions is duplicated, although this is not the case at run time (since the run time will be version 2.0). Changing the .NET version of the application pool is performed because it does not matter for this problem, since this only applies to the runtime of the application.
This seems to be due to the restriction on using Powershell to use CLR 2.0, however this will not work for .NET 4.0 applications, which then report the absence of a partition definition. Therefore, fixing a problem for one version creates a problem in another version.
My question is, has anyone experienced this before and are there any issues allowing Powershell to configure IIS when applications use mixed versions of .NET?
I spent many hours on this problem and therefore really appreciate any help.
UPDATE: There is still no this error, and I think that due to the lack of comments, this is not easy.
I was looking through the IIS 8 Powershell documentation and could see that they added the Clr property to the Set-WebConfiguration command, but this has no effect, because the element I'm trying to change (in this case, HTTP redirection) is in the applicationhost file. config and Powershell gives a warning:
WARNING: Ignoring -Clr value when PSPath is not 'MACHINE/WEBROOT' or 'MACHINE'.
If the modification does not apply to the machine.config file, nor to the root web.config.
It seems that this is not happening (I believe this is a mistake). Perhaps renaming the web.config file in the application directory before any updates - the answer to the Powershell question will not try to parse the configuration. Any thoughts that anyone appreciated on this.