回发后编码损坏
我有一个查询字符串,其参数值包含编码为 %e5
的挪威语字符 å
。该页面包含一个带有 action 属性的表单,该属性由 ASP.Net 自动填充。当 URL 输出到所述属性时,它会以完整的两字节编码打印:%u00e5
。
当回发时,在调试后面的代码时这似乎没问题。但是,该页面实际上会重定向到自身(由于某些其他原因),并且重定向位置标头如下所示: Location: /myFolder/MyPage.aspx?Param1=%C3%A5
因此 %e5
已转换为 %C3%A5
,这会以某种方式破坏输出。
在 HTML 文本中,通过 HttpUtility.HtmlEncode 输出后,损坏的字符看起来像 Ã¥
。
整个 Web 应用程序均采用 ISO8859-1 编码。
附言。在发布表单之前,从操作属性中的输出 %u00e5
中删除 u00 时,所有内容都会很好地输出。但错误似乎是从 %e5
到 %C3%A5
的翻译。 (当然还有自我重定向,但那是另一回事。)
有什么指示吗?
I have a query string with a parameter value that contains the norwegian character å
encoded as %e5
. The page contains a form with an action attribute which is automatically filled by ASP.Net. When the URL is output into said attribute it is printed with a full two byte encoding: %u00e5
.
When posting back this seems to be ok when debugging the code behind. However the page actually does a redirect to itself (for some other reason) and the redirect location header looks like this: Location: /myFolder/MyPage.aspx?Param1=%C3%A5
So the %e5
has been translated to %C3%A5
which breaks the output somehow.
In HTML text the broken characters look like å
after having been output via HttpUtility.HtmlEncode.
The entire web application is ISO8859-1 encoded.
PS. When removing the u00 from the output %u00e5
in the action attribute before posting the form, everything is output nicely. But the error seems to be the translation from %e5
to %C3%A5
. (And of course the self redirect, but that's another matter.)
Any pointers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终得到的解决方案是手动编码重定向 URL。
url.AddQueryItem 基本上执行 HttpContext.Server.UrlDecode(queryParamValue) 操作,而 url.ToString 构建查询字符串,并为每个查询项执行 HttpContext.Server.UrlEncode(queryParamValue) 操作。
UrlBuilder 是我们库中已经存在的一个类,因此一旦我发现问题并意识到 C#/.Net 没有为此提供工具,就可以快速编写修复程序:)
The solution I ended up with was encoding the redirect URL manually.
The url.AddQueryItem basically does HttpContext.Server.UrlDecode(queryParamValue) and the url.ToString builds the query string and for each query item does HttpContext.Server.UrlEncode( queryParamValue).
The UrlBuilder is a class already present in our library, so once I found the problem and realized that C#/.Net didn't provide tools for this, coding the fix was quick :)