【问题标题】:How do I redirect this url pattern in asp.net webforms or asp.net mvc?如何在 asp.net webforms 或 asp.net mvc 中重定向此 url 模式?
【发布时间】:2010-11-01 16:52:34
【问题描述】:

当用户以这种格式填写 URL 时,我试图重定向用户:

http://example.com/http://example2.com/

致以下:

http://example.com/?m=example2.com#http%3A%2F%2Fwww.example2.com%2F

我想去掉 example2 的 host 并使其成为一个查询字符串,然后 URL 编码 example2 的完整 URL 并将其作为锚。

在 asp.net 中执行此操作的最佳方法是什么?我可以使用 mvc、iis7 或 iis6。我知道我可以通过在 IIS6 中将所有内容映射到 .NET 然后使用 httpcontext.rewritepath 来做到这一点,但我敢打赌有更好的方法。

谢谢。

【问题讨论】:

    标签: asp.net asp.net-mvc iis-7 iis-6 url-rewriting


    【解决方案1】:

    不幸的是,ASP.NET 不允许在 URL 路径中的任何位置使用冒号。甚至没有转义的冒号 (%3A)。它只允许在路径的查询字符串部分。

    这个限制甚至在 URL 重写发生之前就已经存在。 (你会得到400 Bad Request error。)在那个问题中,提问者用Stefan from the ASP.NET team的链接回答了他们自己的问题。

    当然,您仍然可以以任何您喜欢的方式从用户那里收集 URL,并以 ASP.NET 可以使用的方式格式化 URL 或重定向。

    【讨论】:

      【解决方案2】:

      您如何看待 ASP.net 的 urlrewritting 概念。我认为它可以解决您的目的

      【讨论】:

      • 当我的朋友告诉我有关 stackoverflow 时,我不知道它会这么有用:)
      • 即使在我开始的时候,我也不知道它是否有用
      猜你喜欢
      • 2011-01-27
      • 2010-10-02
      • 2011-01-15
      • 1970-01-01
      • 1970-01-01
      • 2013-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多