我有兩個IIS網站,即 「accounts.example.com」 這是在使用ASP.NET MVC 3 Web應用程序的Visual Studio 2010中創建和 「api.example.com」 使用了「WCF REST的Visual Studio 2010中創建服務應用程序「。如何使用powershell配置IIS網站的身份驗證(託管WCF REST服務應用程序)?
我創建了一個PowerShell腳本配置環境。創建一個網站的功能如下所示:
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
}
及其調用如下:
create-website $accounts "..\src\accounts"
create-website $api "..\src\api\"
當我運行該腳本,該賬戶的網站是否正確配置(包括認證)。但是,嘗試配置的API的網站時,我得到以下錯誤:
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
這是我不清楚什麼可能導致此錯誤開始,因爲與它好工作的「戶口」網站上。看着谷歌,一些人建議檢查網站是否使用運行.NET 4的應用程序池。我證實腳本成功設置了這一點。
我應該如何配置使用PowerShell的IIS網站的認證?
這是一個錯字嗎?應該是匿名的,而不是匿名的 – 2012-03-10 04:38:29
就「匿名訪問」而言,「accounts」網站的配置是正確的。我改變了外殼,但行爲完全一樣。所以它看起來不區分大小寫。 – bloudraak 2012-03-10 06:17:05