url路由到小写如何?

Iam*_*ker 9 asp.net-mvc asp.net-mvc-3


我在asp.net mvc3上开发了一个Web应用程序,现在我需要制作路由,小写
示例:

 that's what i have:
 http://www.example.com/SubFolder/Category/Index => looks ugly :-)

 that's how i would like it:
 http://www.example.com/subfolder/category/index
Run Code Online (Sandbox Code Playgroud)

我发现这篇文章:http:
//goneale.com/2008/12/19/lowercase-route-urls-in-aspnet-mvc/

我实际上需要使用页面底部的global.asax中的代码.

protected void Application_BeginRequest(Object sender, EventArgs e)   
{
    string lowercaseURL = (Request.Url.Scheme + "://" + 
    HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.Url.AbsolutePath);
    if (Regex.IsMatch(lowercaseURL, @"[A-Z]"))
    {
      lowercaseURL = lowercaseURL.ToLower() + HttpContext.Current.Request.Url.Query;
      Response.Clear();
      Response.Status = "301 Moved Permanently";
      Response.AddHeader("Location", lowercaseURL);
      Response.End();
    }
}
Run Code Online (Sandbox Code Playgroud)

现在的问题是:
什么时候在开发站上使用它的工作是完美的,但当我上传它,生产它不起作用.

在开发站,它只发布,但在生产它有两个:

POST - status: 301 Moved Permanently 
GET  - status: 200 OK
Run Code Online (Sandbox Code Playgroud)

而且我根本没有被重定向到正确的路线.在开发站,它的工作完美.

Iam*_*ker 4

protected void Application_BeginRequest(Object sender, EventArgs e)
{
    string lowercaseURL = (Request.Url.Scheme + 
    "://" +
    HttpContext.Current.Request.Url.Authority +
    HttpContext.Current.Request.Url.AbsolutePath);
    if (Regex.IsMatch(lowercaseURL, @"[A-Z]"))
    {
        System.Web.HttpContext.Current.Response.RedirectPermanent
        (
             lowercaseURL.ToLower() + HttpContext.Current.Request.Url.Query
        );
    }
}
Run Code Online (Sandbox Code Playgroud)