【问题标题】:IIS URL Rewrite For URL Link with %3D使用 %3D 的 URL 链接的 IIS URL 重写
【发布时间】:2013-11-01 02:11:36
【问题描述】:

我遇到了一个问题,有人为我的 asp.net mvc3 站点发布了一个 URL,该 URL 在我的 id 参数后包含 %3D 而不是等号,如下所示:http://ultimategamedb.com/Article/Article?id%3D398210c1-529e-4909-9793-a11b8a832dcc。我尝试了各种重写规则,但似乎无法将 URL 正确重写为:http://ultimategamedb.com/Article/Article?id=398210c1-529e-4909-9793-a11b8a832dcc。这是一个问题,因为带有 %3D 的 URL 给出了 404 错误。如果可能的话,我想创建一个规则,将使用 % 编码的任何 URL 重写为正确的解码值。如果这不可能,我只想知道如何重写我的文章 URL,以确保 %3D 永远不会再次出现在文章 URL 中的等号中。

谁能向我解释我将如何创建这些重写规则?提前致谢!

【问题讨论】:

    标签: asp.net asp.net-mvc-3 iis url-rewriting rewrite


    【解决方案1】:

    你有几个选择:

    1. 编写您自己的提供程序,将 %3D 替换为 =。

      参考:http://www.iis.net/learn/extensions/url-rewrite-module/developing-a-custom-rewrite-provider-for-url-rewrite-module

    2. 在Application_BeginRequest,替换你的路径:

      protected void Application_BeginRequest(object sender, EventArgs e)
      {
          string path = HttpContext.Current.Request.Url.PathAndQuery;
      
          // Search for %3D and replace.
          path = path.Replace("%3D","=");
      
          HttpContext.Current.RewritePath(path);
      }
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-04
      • 2023-03-30
      • 2015-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-27
      相关资源
      最近更新 更多