我有两个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