我有一个正在停用的 Web 应用程序,我正在尝试将对旧应用程序的所有请求重定向到特定页面(显示替换链接和一条消息,建议用户更新他们的书签)。
我已经使用这个问题的答案在 web.config 中设置了一个 HTTP 重定向:ASP.NET httpRedirect : redirect all pages except one除非用户输入网站根文件夹的 URL 时省略尾部斜杠,否则它会工作,在这种情况下,它会转到树上的下一个目录,例如:
原始站点根目录:[domain]/foo/bar/
[domain]/foo/bar/specificpage.aspx
重定向到 [domain]/foo/bar/Default.aspx
(OK)
[domain]/foo/bar/
重定向到 [domain]/foo/bar/Default.aspx
(确定)
[domain]/foo/bar
重定向到 [domain]/foo/Default.aspx
(不行)
这是相关的 web.config:
<system.webServer>
<httpRedirect enabled="true" destination="~/Default.aspx" httpResponseStatus="Permanent">
<add wildcard="/" destination="Default.aspx" />
</httpRedirect>
</system.webServer>
<location path="Default.aspx">
<system.webServer>
<httpRedirect enabled="false" />
</system.webServer>
</location>
当用户访问 [domain]/foo/bar
时,我如何让它工作?
最佳答案
郑重声明,我通过将重定向 URL 设置为文件的绝对路径(包括网站根目录所在的虚拟目录)来修复此问题:
<system.webServer>
<httpRedirect enabled="true" destination="/foo/bar/Default.aspx" httpResponseStatus="Permanent" exactDestination="true">
<add wildcard="/" destination="Default.aspx" />
</httpRedirect>
</system.webServer>
<location path="Default.aspx">
<system.webServer>
<httpRedirect enabled="false" />
</system.webServer>
</location>
关于asp.net - IIS 重定向在没有尾部斜线的情况下无法工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38703502/