0

我正在使用 Visual Studio 2008(我坚持使用此版本)进行 SEO 友好的重定向,如下所示:

公共静态类 RedirectExtension
    {
        public static void RedirectPermanent(这个 HttpResponse 响应,字符串 pathUrl)
        {
            响应。清除();
            response.Status = "301 永久移动";
            response.RedirectLocation = pathUrl;
            响应。结束();
        }
    }
}

重定向是通过在下拉列表中选择一个项目发生的,该下拉列表显示标志图像(使用流行的 jquery 下拉扩展)和选定的区域。对于某些选择,由于我们没有所选区域的子域,我重定向到同一个地方。(由于未知的原因,我被迫重定向,否则会显示页面名称,这是 SEO 人员不想要的。)

我需要传递以某种方式选择的索引,以便我可以生成下拉列表的适当第一项。我总是显示第一个项目。(我不想强制选择一个项目,因为这会进入无限重定向和选择循环。)

我能做的事情非常有限,因为一切都在我继承的一个可怕的旧站点中运行,我什至无法调试。

4

2 回答 2

0

一种简单的方法是将索引作为查询字符串参数添加到 Url,例如:

public static void RedirectPermanent(this HttpResponse response, string pathUrl, int selectedIndex)
{
    response.Clear();
    response.Status = "301 Moved Permanently";
    response.RedirectLocation = pathUrl + "?index=" + selectedIndex.ToString();
    response.End();
}
于 2012-09-25T12:26:30.100 回答
0

如果查询字符串不起作用,最后一种方法是使用 cookie。在重定向之前设置 cookie。根据要求,您应该检查是否设置了 cookie。

于 2012-09-25T13:39:51.437 回答