【发布时间】:2016-09-13 17:29:32
【问题描述】:
我有一个托管在 Azure 中的网站,将使用 URL https://abc.cloudapp.net/controller1/action1/parameter1 访问该网站
我的客户想要以下。
当我们尝试访问网址“https://abc.cloudapp.net”时,它应该会自动将我重定向到上述网站的实际网址。
我希望使用 web.config 来实现这一点。我尝试了几种组合(下面列出了其中的几种)。
组合一:
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to Full URL" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{URL}" pattern="^abc.cloudapp.net$" />
</conditions>
<action type="Redirect" url="https://abc.cloudapp.net/controller1/action1/parameter1" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
组合2:
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to Full URL" stopProcessing="true">
<match url="https://abc.cloudapp.net" />
<action type="Redirect" url="https://abc.cloudapp.net/controller1/action1/parameter1" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
这些组合都不起作用。 我在下面发布了针对此问题的解决方法。 但是,我需要一些快速帮助才能获得永久解决方案。 我仍然需要这方面的帮助,请有人帮忙。
【问题讨论】:
-
redirectType="Permanent"将发出301 Permanent请求。这些是可缓存的。在浏览器中。对资源的任何后续请求都将从缓存重定向,甚至不会向原始服务器发出请求。这使得调试非常混乱。坚持使用302 Found,直到你让它工作:redirectType="Found"并弄清楚如何使用flush those nasty 301 responses out of your browser's cache。
标签: c# asp.net-mvc asp.net-mvc-4 azure http-redirect