Azure webapp Web.config httpErrors未重定向

时间:2018-01-12 21:23:25

标签: web-config azure-web-sites http-error

我有一个Azure托管的网站,效果很好。我坚持的事情是希望在基本URL之后忽略任何内容,并且始终让用户看到 整个站点的单个页面。 (如果他们输入http://example.com网站,之后的任何内容都将被忽略,我的map.html页面将会显示。

我对Web.config文件进行了以下更改,这有助于此:

type

如果我输入example.com/xxxx.yyyy的网址,该网站显示正常(它会忽略" /xxxx.yyyy"并显示map.html页面 - 正是我想要的。但是如果我输入example.com/xxxx而没有跟踪" .yyyy")以下IIS或Azure消息显示:

<system.webServer>
  <defaultDocument enabled="true">
    <files>
      <clear />
      <add value="map.html" />
    </files>
  </defaultDocument>
  <httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL">
    <remove statusCode="404" subStatusCode="-1" />
    <error statusCode="404 path="/map.html" responseMode="ExecuteURL" />
  </httpErrors>
</system.webServer>

无论网址中的网站名称如何,我怎样才能获得相同的重定向?

我尝试过Windows Edge,Chrome和Safari,但它们都给出了相同的结果。

1 个答案:

答案 0 :(得分:0)

要实现您的要求,您可以添加重写规则:

<system.webServer>
  <rewrite>
    <rules>
      <rule name="Rewrite to map">
        <action type="Rewrite" url="/map.html"/>
      </rule>
    </rules>
  </rewrite>

更新

如果您在ASP.NET中工作,您可能还需要在Web.config中指定<customErrors> Element

<?xml version="1.0" encoding="UTF-8"?>

<configuration>
  <system.web>
    <customErrors mode="On">
      <error statusCode="404" redirect="~/map.html" />
    </customErrors>
  </system.web>

  <system.webServer>
    <defaultDocument enabled="true">
      <files>
        <clear />
        <add value="map.html" />
      </files>
    </defaultDocument>
    <httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL">
      <remove statusCode="404" subStatusCode="-1" />
      <error statusCode="404" path="/map.html" responseMode="ExecuteURL" />
    </httpErrors>
  </system.webServer>
</configuration>