我有一个asp.net应用程序,必须在SSL下运行,并且在web.config中定义了一些重写规则来实现这一目的。
<!--file web.config -->
....
</system.webServer>
<rewrite>
<rules configSource="webrewrite.config" />
</rewrite>
</system.webServer>
<!--file web.config -->
<rules>
....
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
....
</rules>
但是,在开发模式下(使用本地Web服务器或IIS Express),我不想使用SSL。 所以我希望能够使用web.config转换来删除一个或多个重写规则(但不是全部)
答案 0 :(得分:4)
我通过使用Remove transform解决了这个问题,如下所示
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
....
<system.webServer>
<rewrite>
<rules>
<rule name="RulaNameToRemove"
xdt:Transform="Remove"
xdt:Locator="Match(name)" >
</rule>
</rewrite>
</system.webServer>
</configuration>
答案 1 :(得分:1)
如果要删除Dev Configuration的整个部分,请使用
List<List<string>> filters = Enumerable.Range(0, 101)
.SelectMany(a => Enumerable.Range(0, 101).Select(b => "A{0:00}B{1:00}"))
.Select(i => Enumerable.Range(0, 10).Select(c => string.Empty).ToList())
.SelectMany(a => Enumerable.Range(0, 101).Select(b => "{0:000}"))
.SelectMany(a => Enumerable.Range(0, 101).Select(b => "{0:00}"))
.SelectMany(a => Enumerable.Range(0, 1).Select(b => "hello"))
.ToList();
List<string> matches = new List<string>();
// Sentence
string sentence = "This is a A05B09 hello 02 100 test";
string newSentence = string.Empty;
// Find Matches
for (int i = 0; i < filters.Count; i++)
{
// Add to Matches List
if (sentence.Contains(filters[i].ToString()))
{
matches.Add(filters[i]);
}
}
// Filter Sentence
newSentence = Regex.Replace(
sentence
, @"(?<!\S)(" + string.Join("|", matches) + @")(?!\S)"
, ""
, RegexOptions.IgnoreCase
);
// Display New Sentence
Console.WriteLine(newSentence);
答案 2 :(得分:0)
您可以将发布设置移至web.config.release文件
答案 3 :(得分:0)
请在下面编写代码web.Debug和web.Release配置文件。 Web.Debug将删除重写规则,而Web.Release将插入重写规则。
Web.Debug.config
<system.webServer>
<rewrite>
<rules>
<rule name="RulaNameToRemove"
xdt:Transform="Remove"
xdt:Locator="Match(name)" >
</rule>
</rewrite>
</system.webServer>
</configuration>
Web.Release.config
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" stopProcessing="true" xdt:Transform="Insert">
<match url=".*"/>
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true"/>
</conditions>
<action type="Redirect" url="https://{SERVER_NAME}" redirectType="Permanent"/>
</rule>
</rules>
</rewrite>
</system.webServer>