asp.net - Powershell:更新 IIS web.config

标签 asp.net powershell iis ssl cookies

需要更新 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/

相关文章:

c# - 在哪里放置带有 API key 的 JSON 文件以进行私有(private)访问

c# - 在 aspx 上获取 ascx

asp.net - Google 404 和 .NET 自定义错误页面

asp.net - 未找到 aspnet_regiis 部分

powershell - 为什么 Powershell Import-Csv 无法在此 CSV 文件上正常工作?

powershell - 从PowerShell运行控制台EXE:本地和远程 session 中输出的不同行为

tomcat - SiteMinder FCC header 变量出现在 IIS 中但不出现在 AJP 连接的 Tomcat 中

javascript - 防止在 ASP.NET 中选择默认值时发生下拉菜单的 Selected Index Changed 事件

asp.net - 无法加载文件或程序集 System.Web.Entity... - 我缺少什么?

powershell - 从 ServiceNow 检索用户名