Web.config中的Asp.Net RequireSSL

Ask*_*_SO 2 c# asp.net asp.net-mvc web-config

我们的应用有三种不同的环境,如Test,SIT和Prod.在Test中我们有HTTP,剩下的两个我们有HTTPS.

要为cookie设置安全属性,我们在Web.config文件中添加了以下代码行.但是在测试环境中我们不需要这个代码.

 <httpCookies requireSSL="true" />
Run Code Online (Sandbox Code Playgroud)

想在SIT和Prod中使用此代码但不在Test中.是否可以在特定环境的Web.config文件中包含此代码.

Ver*_*dus 5

是的,您可以使用转换来处理不同的环境.假设您为每个环境构建项目.

然后添加一个新文件web.Test.config,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <system.web>
        <httpCookies requireSSL="false" xdt:Transform="Replace" />
    </system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)

请参阅https://bitwizards.com/Thought-Leadership/Blog/2014/November-2014/7-Steps-to-Setup-Web-Config-Transformations