301从以前的应用版本重定向

时间:2010-07-02 13:42:59

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

我找到了这个。 http://geekswithblogs.net/shahed/archive/2007/10/23/116278.aspx

有些人可以帮我把它组织成一个aspx / aspx.cs文件,因为我对这里的所有代码都不太熟悉。

您好,

我使用asp.net构建了一个新网站。以前的版本是使用asp构建的。这是问题所在。我的客户希望在包含查询字符串的页面上进行301永久重定向。

如何从我的服务器上不存在的页面重定向,例如。

来自

www.example.com/dolls/detail.asp?id=15

www.example.com/search_results.aspx?section=Dolls&title=Hat

我已阅读了一些文章,但他们没有解释如何解决这个特殊问题。

非常感谢, ç

1 个答案:

答案 0 :(得分:0)

1)Apache:Redirect 301 /detail.asp?id=15 http://www.mydomain.com/search_results.aspx?section=Dolls&title=Hat

2)IIS:有一个重定向页面。

3)已修改:完整代码:

using System.Web;
public class PermaRedirectHandler : IHttpHandler
{
    public PermaRedirectHandler(){}

    public void ProcessRequest(HttpContext context)
    {
        Response.Status = "301 Moved Permanently";
        Response.RedirectLocation = RedirectionClass.GetRedirectUrl(context);
    }

    public bool IsReusable { get { return false; } }
}

在Web配置中,您将所有以.asp结尾的路径映射到处理程序:

<system.webServer>
  <handlers>
    <add verb="*" path="*.asp" name="redir" type="PermaRedirectHandler" modules="IsapiModule"/>
  ...
  </handlers>
</system.webServer>

您需要旧的=&gt;新网址RedirectionClass.GetRedirectUrl的映射器。您可以使用Dictionary<string, string>或其他任何内容。