【问题标题】:MVC3 URL Encoding Issue with Slash (/) %2f - Passing a slash in query string with MVC Routing带有斜杠 (/) %2f 的 MVC3 URL 编码问题 - 使用 MVC 路由在查询字符串中传递斜杠
【发布时间】:2013-01-31 16:51:44
【问题描述】:

我在 global.asax 中定义了以下路由路径来处理 url 中的两个参数:

routes.MapRoute(
                "Default", // Route name
                "{page}/{th}", // URL with parameters
                new { controller = "Home", action = "Index", page = UrlParameter.Optional, th = UrlParameter.Optional } // Parameter defaults
            );

第一个参数是另一个网站的URL,即www.othersite.com/about/。

即使我将斜杠编码为 %2f,它也无法正确路由 URL。我想使用这样的东西:

http://{mywebsite}/www.othersite.net%2fabout%2f/{parameter2}

想使用 Base64 编码,因为我希望 URL 像上面那样可读。

我正在使用 MVC 3。

谢谢

【问题讨论】:

    标签: asp.net-mvc-3 url-rewriting url-routing


    【解决方案1】:

    查看 Scott Hanselman 的 following blog post,他在其中解释了一些可能的解决方法。但结论是:

    经过所有努力在请求路径中获得疯狂的东西之后,它是 值得一提的是,只需将值保留为查询的一部分 字符串(还记得这篇文章开头的 WAY 吗?)更容易, 更清洁、更灵活、更安全。

    因此,基本上最好为此使用 url 编码的查询字符串参数,而不是试图在一场你可能会输掉的战斗中与 IIS 作斗争。

    【讨论】:

      猜你喜欢
      • 2013-02-11
      • 2010-12-29
      • 2023-03-24
      • 2015-09-06
      • 1970-01-01
      • 1970-01-01
      • 2015-09-07
      • 2016-11-29
      • 2012-06-23
      相关资源
      最近更新 更多