1

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?

bloudraak
  • 5,902
  • 5
  • 37
  • 52
  • Is that a typo? Should be anonymous, not Anonymous – Lex Li Mar 10 '12 at 04:38
  • The "accounts" website is correctly configured as far as the anonymous access is concerned. I changed the casing, but the behavior is exactly the same. So it looks like its not case sensitive. – bloudraak Mar 10 '12 at 06:17

1 Answers1

0

Have you tried the MS hot fix for IIS 7.5? It includes a fix for "You cannot use WMI to manage .NET Framework 4.0 configurations." The hot fix solved the same Standard Endpoints error with WCF REST-ful service for Mike.

What Would Be Cool
  • 6,204
  • 5
  • 45
  • 42