【问题标题】:How does one configure the authentication of an IIS website (hosting a WCF REST service application) using powershell?如何使用 powershell 配置 IIS 网站(托管 WCF REST 服务应用程序)的身份验证?
【发布时间】:2012-03-10 03:17:34
【问题描述】:

我有两个 IIS 网站,即使用 ASP.NET MVC 3 Web 应用程序在 Visual Studio 2010 中创建的“accounts.example.com”和使用“WCF”使用 Visual Studio 2010 创建的“api.example.com” 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

我不清楚是什么导致了这个错误,因为它在“帐户”网站上运行良好。查看 google,有人建议检查网站是否使用运行 .NET 4 的应用程序池。我验证脚本成功设置了它。

我应该如何使用 Powershell 配置 IIS 网站的身份验证?

【问题讨论】:

  • 是错字吗?应该是匿名的,而不是匿名的
  • 就匿名访问而言,“帐户”网站已正确配置。我更改了大小写,但行为完全相同。所以看起来它不区分大小写。

标签: powershell iis-7.5


【解决方案1】:

你试过MS hot fix for IIS 7.5吗?它包括对“您不能使用 WMI 管理 .NET Framework 4.0 配置”的修复。热修复解决了与WCF REST-ful service for Mike. 相同的标准端点错误

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-05
    • 2012-02-17
    • 2011-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多