301重定向在Asp.Net MVC

问题描述:

我有一个多元文化MVC2网站。
其实我的主页可以用下面的路径来访问:

I have an Multiculture MVC2 website. Actually my home page can be accessed with the following paths:

http://mydomain.com
http://mydomain.com/
http://mydomain.com/en
http://mydomain.com/en/
http://mydomain.com/en/home
http://mydomain.com/en/home/

我要的是,上述所有路径进行301重定向到以下内容:

What I want is that all the above paths make a 301 redirect to the following:

http://mydomain.com/en

,这样我就不必不同的URL之间共享的PageRank。

so that I don't have to share pagerank between different urls.

注意,连接字符串是动态的,并设置文化为网站。

Note that the en string is dynamic and sets the culture for the website.

我Asp.Net MVC是新的,有人可以张贴一些code这样做呢?
谢谢

I'm new in Asp.Net MVC, someone could post some code to do that? Thanks

像这样

public class PermanentRedirectResult : ViewResult
{
    public string Url { get; set; }

    public PermanentRedirectResult(string url)
    {
        if (string.IsNullOrEmpty(url))
            throw new ArgumentException("url is null or empty", url);
        this.Url = url;
    }

    public override void ExecuteResult(ControllerContext context)
    {
      if (context == null)
        throw new ArgumentNullException("context");
      context.HttpContext.Response.StatusCode = 301;
      context.HttpContext.Response.RedirectLocation = Url;
      context.HttpContext.Response.End();
    }
}

和与此称之为

返回新
  PermanentRedirectResult(/ myurl);

return new PermanentRedirectResult("/myurl");