在asp.net web.config

时间:2016-04-22 06:40:21

标签: asp.net asp.net-mvc redirect web-config http-error

我有一个网址/example/index.html,点击后,我需要重定向到页面的根目录/

问题是这个页面实际上并不存在,所以我只是得到了404。 我希望在web.config文件中执行此操作,如果可能的话。这就是我所拥有的:

<location path="example/index.html">
  <system.webServer>
    <httpRedirect enabled="true" destination="/" httpResponseStatus="Permanent" />
  </system.webServer>
</location>

但似乎404处理首先触发。有什么想法吗?

2 个答案:

答案 0 :(得分:0)

在system.webServer标记内使用此选项。它为我工作:

<httpRedirect enabled="true" exactDestination="true">
    <add destination="/" wildcard="*/home/test.html" />
</httpRedirect> 

答案 1 :(得分:0)

HTTP重定向在IIS 7及更高版本的默认安装中不可用。要安装它,请在HTTP Redirection下启用Common HTTP Features。各种操作系统的所有步骤都列在https://docs.microsoft.com/en-us/iis/configuration/system.webserver/httpredirect/