【问题标题】:301 Redirect Classic ASP requests to ASP.NET MVC 5301 将经典 ASP 请求重定向到 ASP.NET MVC 5
【发布时间】:2015-09-08 15:22:20
【问题描述】:

我的任务是弄清楚如何处理经典 ASP 站点到新 ASP.NET MVC 5 应用程序的 301 重定向。域名将保持不变。

我需要做的示例:

Old Url:
http://www.example.com/index_cityname.asp

New Url (MVC):
http://www.example.com/cityname

系统很可能使用 IIS 8.x。我正在 Windows 8.1 机器上开发,并且在功能中启用了 ASP。但是当我在浏览器中输入 .asp 扩展名时,我得到了 404。

我构建了一个自定义组件来分析传入的请求,然后检查一个列表,如果它存在,它将新的 Response.RedirectPermanent(newPath, true) 映射到新路径。唯一的问题是,它永远不会被击中。在生命周期的早期某个地方,应用程序看到它是一个 .asp 请求,然后退出。

关于如何使用相同的域名使 301 重定向从经典 ASP 到 ASP.NET MVC 5 的任何想法?

【问题讨论】:

    标签: asp.net-mvc redirect asp-classic


    【解决方案1】:

    尝试将以下内容添加到您的 web.config 文件中:

    <modules runAllManagedModulesForAllRequests="true" />
    

    它属于system.webServerconfiguration

    但请注意使用此设置的性能和其他问题。见http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html

    【讨论】:

      【解决方案2】:

      您可以使用 web.config 中的规则直接重定向。我试图编写您的用例,但也许您必须调整匹配规则或目标操作以满足您的需要。

      将此添加到您的 web.config:

          <configuration>
              <system.webServer>
                  <rewrite>
                      <rules>
                          <rule name="redirect classic asp" stopProcessing="true">
                              <match url="index_(\w+)\.asp$" />
                              <action type="Redirect" url="{R:1}" appendQueryString="true" />
                          </rule>
                      </rules>
                  </rewrite>
              </system.webServer>
          </configuration>
      

      我无法深入了解 web.config 重写规则的所有细节,但我能找到的最好(简单)文档在这里:Learn.IIS Rewrite Module

      这里也有参考:Rewrite Module Reference

      【讨论】:

        猜你喜欢
        • 2023-03-10
        • 2016-05-11
        • 1970-01-01
        • 1970-01-01
        • 2011-06-25
        • 1970-01-01
        • 2012-06-12
        • 2013-05-17
        • 2011-01-11
        相关资源
        最近更新 更多