【问题标题】:Powershell: Updating IIS web.configPowershell:更新 IIS web.config
【发布时间】:2015-11-12 02:24:37
【问题描述】:

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

Web.Config 当前包含以下 sn-p。

<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'}

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

【问题讨论】:

  • see
  • 您链接以直接修改 XML 的问题的两个答案。不推荐这样做,因为没有架构验证,并且通过更改 XML 可能会破坏您的网站。
  • @Peter-Hahndorf 这两项更改均已成功测试并推荐使用。如果不以这种方式进行更改,对于大型农场,您会如何建议?
  • FredrickCampbell - 我并不是说它们不工作,如果你非常小心,直接修改 XML 可以工作,但是如果你拼错了属性的名称,你的脚本工作得很好,但是该网站将被打破。有一个用于更改 IIS 配置的 COM API。在 WMI、托管代码、PowerShell 和 appcmd.exe 中都有它的包装器。哦,我说的是劳埃德的链接,而不是你的问题。我注意到我忘记了@lloyd
  • @Peter-Hahndorf 感谢您的反馈,尝试您的解决方案。您的解决方案效果很好 +1。

标签: asp.net powershell iis ssl cookies


【解决方案1】:

对于需要SSL

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 替换为您的网站名称。

【讨论】:

  • 啊,那是票。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-03-29
  • 2016-04-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多