我尝试从我们的某个Web服务中删除特定的IIS授权规则。我需要使用“允许”模式删除用户“所有用户”。
我尝试使用此命令
Clear-Webconfiguration -Filter /system.webServer/security/authorization -Force -PSPath 'IIS:\sites\IAI Application Customizer'
我可以删除所有创建的规则,但只有“所有用户”规则仍然存在。
我希望你能帮我解决这个问题。谢谢
您必须两次调用Clear-WebConfiguration
才能删除所有继承的规则。例:
Clear-WebConfiguration -Filter "/system.webServer/security/authorization/add[@users='*' and @roles='' and @verbs='']" -PSPath "IIS:\Sites\my_site"
Clear-WebConfiguration -Filter "/system.webServer/security/authorization/add[@users='*' and @roles='' and @verbs='']" -PSPath "IIS:\Sites\my_site"
Add-WebConfiguration -Filter "/system.webServer/security/authorization" -Value (@{AccessType="Allow"; Users="my_user"; Permissions="Read, Write"}) -PSPath "IIS:\Sites\my_site"
也许你可以为该服务更改web.config
文件。
<authorization>
<remove accessType="Allow" users="*" />
</authorization>
这是我的解决方案。
$webConfigPath = "C:\Users\SOGL_D\Desktop\test.xml"
$xml = [xml](get-content $webConfigPath) # Create XML object and open the web.config file
foreach( $item in $xml.configuration."system.webServer".security.authorization.add ) # Traverse through all modules
{
if( $item.users -eq "*" ) # Checking if the current module is to be removed
{
$xml.configuration."system.webServer".security.authorization.RemoveChild($item); # Remove the desired module when found
}
}
$xml.Save($webConfigPath) # Save the updated web.config file
这对我有用:
C:\ Windows \ System32 \ inetsrv \ appcmd.exe set config /section:system.webServer/security/authorization / - “[accessType ='Allow',users ='*']”