Configuring IIS with Powershell - Enable Forms Authentication

断了今生、忘了曾经 提交于 2019-12-10 17:38:19

问题


My IIS looks like this:

Sites ->
        Default Web Site ->
                            MyWebApp

Then the question is: How do I enable Forms Authentication on MyWebApp? I mange to change or edit Anonymous Access, Basic, and Windows Auth. However, Forms Auth is not that easy. How do I do this in Powershell?

I'm able to read the setting this way:

(Get-WebConfiguration system.web/authentication 'IIS:\sites\Default Web Site\MyWebApp').Mode

I'm having trouble or no luck with Set-Webconfiguration, or Set-Webconfigurationproperty. I find these cmdlets hard to figure out.

Change happens in web.config, at least the web.config updates when I hit Enable or Disable on Forms Authentication at the IIS manager. Any clues and tips are highly appreciated.


回答1:


You pipe the authentication configuration settings to Set-Webconfiguration giving the appropriate filter after you modify your properties:

$config = (Get-WebConfiguration system.web/authentication 'IIS:\sites\Default Web Site')
$config.mode = "Forms"
$config | Set-WebConfiguration system.web/authentication

Note: Backup your config before trying this.




回答2:


Or with a one liner:

Set-WebConfiguration system.web/authentication 'IIS:\sites\Default Web Site' -value @{mode='Forms'}


来源:https://stackoverflow.com/questions/13058537/configuring-iis-with-powershell-enable-forms-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!