URLRewriter 查询字符串中的&符号 [英] Ampersands in URLRewriter Query Strings

查看:25
本文介绍了URLRewriter 查询字符串中的&符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含与号的查询字符串参数值.例如,参数的有效值可能是:

I have a query string parameter value that contains an ampersand. For example, a valid value for the parameter may be:

a & b

当我生成包含参数的 URL 时,我使用 System.Web.HTTPUtility.UrlEncode() 使每个元素对 URL 友好.它(正确地)给了我一个 URL,如:

When I generate the URL that contains the parameter, I'm using System.Web.HTTPUtility.UrlEncode() to make each element URL-friendly. It's (correctly) giving me a URL like:

http://example.com/foo?bar=a+%26b

问题是 ASP.NET 的 Request 对象将(编码的)&符号解释为查询字符串参数分隔符,因此将我的值分成两部分(第一个将bar"作为参数名称;第二个有空名称).

The problem is that ASP.NET's Request object is interpreting the (encoded) ampersand as a Query String parameter delimiter, and is thus splitting my value into 2 parts (the first has "bar" as the parameter name; the second has a null name).

似乎 ASP.NET 首先对 URL 进行 URL 解码,然后在解析查询字符串时使用它.

It appears that ASP.NET is URL-decoding the URL first and then using that when parsing the query string.

解决此问题的最佳方法是什么?

What's the best way to work around this?

更新:问题取决于 URLRewriter(第三方插件)和不是 ASP.NET 本身.我已更改标题以反映这一点,但在我找到有关问题的更多信息之前,我将保留问题文本的其余部分.

UPDATE: The problem hinges on URLRewriter (a third-party plugin) and not ASP.NET itself. I've changed the title to reflect this, but I'll leave the rest of the question text as-is until I find out more about the problem.

推荐答案

切换到 UrlRewritingNet.UrlRewrite 没有没有帮助,因为它显然有相同的错误.我想这毕竟可能与 ASP.NET 有关系.

Switching to UrlRewritingNet.UrlRewrite did not help, as it apparently has the same bug. I'm thinking it might have something to do with ASP.NET after all.

这篇关于URLRewriter 查询字符串中的&符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆