【发布时间】:2024-04-26 02:40:02
【问题描述】:
我正在尝试添加一个 iis url 重写规则,该规则在开发环境中(在我的本地计算机上)不同,并且一旦上传到服务器并发布(部署)。
我的 IIS 重写规则有效,但我不想在部署网站后记住将 localhost 更改为我的服务器托管地址。有什么建议吗?
下面是我在<system.webServer>中的IIS URL重写规则
<!-- IIS Rules Rewrite -->
<rewrite>
<rules>
<!-- Serve site map with proper XML content type response header. -->
<rule name="Sitemap XML" enabled="true" stopProcessing="true">
<match url="sitemap.xml" />
<action type="Rewrite" url="sitemap.aspx" appendQueryString="false"/>
</rule>
<!-- Access block rule - is used to block all requests made to a Web site if those requests do not have the host header set. This type of rule is useful when you want to prevent hacking attempts that are made by issuing HTTP requests against the IP address of the server instead of using the host name -->
<rule name="Fail bad requests">
<match url=".*"/>
<conditions>
<add input="{HTTP_HOST}" pattern="localhost" negate="true" />
</conditions>
<action type="AbortRequest" />
</rule>
<!-- HTTP to HTTPS Rule
<rule name="Redirect to https" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" negate="false" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Found" />
</rule>-->
【问题讨论】:
-
我觉得你可以使用配置文件转换 (msdn.microsoft.com/en-us/library/dd465318(v=vs.100).aspx)
-
感谢@kienct89,这似乎是正确的。我将如何专门针对第二条规则 - 将 localhost 更改为托管地址?
-
我添加了我的答案
标签: c# asp.net visual-studio iis