Powershell:更新IIS web.config [英] Powershell: Updating IIS web.config
问题描述
需要通过添加SSL来更新IIS web.config以保护cookie。
Needing to update IIS web.config to secure cookies by adding SSL.
Web.Config目前包含以下代码段。
Web.Config currently contains the following snippet.
<configuration>
<system.web>
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
</system.web>
</configuration>
想要更新system.web部分如下。
Wanting to update system.web section as follows.
需要修改(假设您将使用Set-WebConfiguration)
Need to modify (Assume you would use Set-WebConfiguration)
<authentication mode="Forms">
to
<authentication mode="Forms" requireSSL="true">
需要添加(假设您将使用Add-WebConfiguration
Need to add (Assume you would use Add-WebConfiguration
<httpCookies httpOnlyCookies="true" />
已成功使用以下内容更新web.config,
Have used the following successfully to update web.config,
Add-WebConfigurationProperty -pspath "iis:\Sites\FMC" -filter "/appSettings" -name "." -Value @{key='fmcDataContextType';value='SqlRepository.fmcDataContext'}
但似乎无法为此目的获得正确的格式。
But can't seem to get the right format for this purpose.
推荐答案
对于 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"
你必须替换默认网站
,包含您网站的名称。
you have to replace Default Web Site
with the name of your site.
这篇关于Powershell:更新IIS web.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!