繁体   English   中英

Powershell:更新IIS web.config

[英]Powershell: Updating IIS web.config

需要通过添加SSL更新IIS web.config以保护cookie。

Web.Config当前包含以下代码段。

<configuration> 
  <system.web> 
       <authentication mode="Forms">
            <forms loginUrl="~/Account/LogOn" timeout="2880" />
       </authentication>
  </system.web> 
</configuration> 

想要更新system.web部分,如下所示。

需要修改(假设您将使用Set-WebConfiguration)

<authentication mode="Forms">
to
<authentication mode="Forms" requireSSL="true">

需要添加(假设您将使用Add-WebConfiguration

<httpCookies httpOnlyCookies="true" />

已成功使用以下内容更新了web.config,

Add-WebConfigurationProperty -pspath "iis:\Sites\FMC" -filter "/appSettings" -name "." -Value @{key='fmcDataContextType';value='SqlRepository.fmcDataContext'}

但是似乎无法为此目的获得正确的格式。

对于requireSSL

Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Default Web Site'  -filter "system.web/authentication/forms" -name "requireSSL" -value "True"

httpOnlyCookies使用:

Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Default Web Site'  -filter "system.web/httpCookies" -name "httpOnlyCookies" -value "True"

用于添加httpOnlyCookies的方法是:

Add-WebConfigurationProperty  //system.web 'MACHINE/WEBROOT/APPHOST/Default Web Site' -Name httpCookies -Value "True"

您必须将Default Web Site替换为您的网站名称。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM