powershell - 在 Powershell 中启用 IIS 应用程序的身份验证

标签 powershell iis web-deployment

我知道如何通过以下命令为 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/

相关文章:

asp.net - 如何将 .lic 文件发布(部署)到 Azure Web 应用服务的根目录?

python - 如何在 Django 1.9.6 中创建 super 用户帐户

powershell - gpg with powershell - 密码安全

powershell - 在powershell中下载网站文件

PowerShell递归删除目录中小于500字节的文件

rest - ServiceStack 使用 IIS 或 Windows 服务的优势

iis - URL 重写 IIS 7.5 - 仅适用于端口 80

asp.net - IIS 会受益于多核 CPU 来处理并发请求(CPU 密集型)吗?

ftp - 自动 FTP 部署 : is there any automatic/programmable tool available?

python - 将大型目录树中的所有文件大小归零(删除文件内容,保留文件)