需要更新 IIS web.config 以通过添加 SSL 来保护 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
替换为您的网站名称。
关于asp.net - Powershell:更新 IIS web.config,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32084445/