我知道如何通过以下命令为 IIS 网站设置此设置:
Set-WebConfigurationProperty -filter "/system.webServer/security/authentication/windowsAuthentication" -name enabled -value true -PSPath "IIS:\" -location $siteName
但我想为该网站内的应用程序设置它。例如,我有一个名为“MySite”的 IIS 网站,其中有两个应用程序。我想为其中一个启用 Windows 身份验证,而不为另一个启用 Windows 身份验证。因此,在站点级别启用将对两者都启用,而这是我不想要的。
最佳答案
我遇到了处理锁定部分的问题,接受的答案建议打开一个 GUI 来解决它,我首先尝试使用 PowerShell 来避免这种情况。
简短回答
启用 Windows 身份验证并禁用匿名身份验证
$iisSiteName = "Default Web Site"
$iisAppName = "MyApp"
Write-Host Disable anonymous authentication
Set-WebConfigurationProperty -Filter '/system.webServer/security/authentication/anonymousAuthentication' -Name 'enabled' -Value 'false' -PSPath 'IIS:\' -Location "$iisSiteName/$iisAppName"
Write-Host Enable windows authentication
Set-WebConfigurationProperty -Filter '/system.webServer/security/authentication/windowsAuthentication' -Name 'enabled' -Value 'true' -PSPath 'IIS:\' -Location "$iisSiteName/$iisAppName"
处理锁定部分
如 IIS documentation 中所述:
Authentication sections are usually locked, i.e. they can't be written to a web.config file but have to be written to the central applicationhost.config file instead.
我们必须使用-PSPath
和-Location
参数。
Set-WebConfigurationProperty -filter /system.webServer/security/authentication/windowsAuthentication -name enabled -value true -PSPath IIS:\ -location DemoSite/DemoApp
关于powershell - 在 Powershell 中启用 IIS 应用程序的身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24535200/