I have two IIS websites, namely "accounts.example.com" that was created in Visual Studio 2010 using the ASP.NET MVC 3 Web Application and "api.example.com" created with Visual Studio 2010 using the "WCF REST Service Application".
I created a powershell script to configure the environment. The function to create a website looks as follows:
function create-website([string]$name, [string]$relativePath) {
$physicalPath = Join-Path -Path $scriptPath -ChildPath $relativePath
$physicalPath = [IO.Path]::GetFullPath( $physicalPath )
# Create an application pool and ensure it is using .NET 4
New-WebAppPool -Name $name
Set-ItemProperty IIS:\AppPools\$name managedRuntimeVersion v4.0
# Create Website
New-WebSite -Name $name -Port 80 -HostHeader $name -PhysicalPath $physicalPath
# Set the Application Pool
Set-ItemProperty IIS:\Sites\$name ApplicationPool $name
Set-ItemProperty IIS:\Sites\$name ApplicationPool $name
# Update Authentication
Set-WebConfigurationProperty -filter /system.WebServer/security/authentication/AnonymousAuthentication -name enabled -value true -location $name
Set-WebConfigurationProperty -filter /system.WebServer/security/authentication/windowsAuthentication -name enabled -value false -location $name
Set-WebConfigurationProperty -filter /system.WebServer/security/authentication/basicAuthentication -name enabled -value false -location $name
}
And its called as follows:
create-website $accounts "..\src\accounts"
create-website $api "..\src\api\"
When I run the script, the accounts website is correctly configured (including authentication). However, when trying to configure the api site, I get the following error:
Set-WebConfigurationProperty : Filename: \\?\S:\example\src\api\web.config
Line number: 20
Error: The configuration section 'standardEndpoints' cannot be read because it is missing a section declaration
At S:\example\scripts\Install-DevelopmentEnvironment.ps1:26 char:33
+ Set-WebConfigurationProperty <<<< -filter /system.WebServer/security/authentication/AnonymousAuthentication -name enabled -value true -location $name
+ CategoryInfo : NotSpecified: (:) [Set-WebConfigurationProperty], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.IIs.PowerShell.Provider.SetConfigurationPropertyCommand
It is unclear to me what could cause this error to begin with since it worked fine on the "accounts" website. Looking at google, some suggested to check if the website is using an application pool running with .NET 4. I verified that the script successfully sets this up.
How should I configure the authentication of an IIS website using Powershell?