ASP.Net URLEn code&符号的查询字符串中使用 [英] ASP.Net URLEncode Ampersand for use in Query String

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

问题描述

我需要重定向到传递参数作为查询字符串的URL。

I need to redirect to a url passing a parameter as a query string.

这可以包括and符中的值。如

This can include an Ampersand in the value. such as

string value = "This & That";
Response.Redirect("http://www.mysite.com/?Value=" + Server.UrlEncode(value));

这howerver回报<一个href=\"http://www.mysite.com/?Value=This+&+That\">http://www.mysite.com/?Value=This+&+That

This howerver returns http://www.mysite.com/?Value=This+&+That

我应该使用符合EN code这个字符串?

What should I be using to encode this string?

编辑:
卢克感谢指点出来的明显,code确实正常工作。我表示歉意,我的问题不是一个有效的问题毕竟!

Thanks Luke for pointing out the obvious, the code does indeed work correctly. I Apologise, my question was not a valid question after all!

我要的页面有很多旧的遗留code的是AP prently做一些编码还挺与解码本身使它看起来好像我urlen code不能正常工作。

The page I was going to had a lot of old legacy code which is apprently doing some kinda of encoding and decoding itself making it appear as if my urlencode was not working.

我的解决方案,不幸的是,完全删除使用的&安培;直至有问题的code可以被重新写入。你不只是讨厌老code!

My solution unfortunately is to completely drop use of an & until the code in question can be re-written. Don't you just hate old code!

推荐答案

借助文档建议该 Server.UrlEn code 要正确处理好与符号。

The documentation suggests that Server.UrlEncode should handle ampersands correctly.

我刚刚测试过你的确切code和返回的字符串是正确的连接codeD:

I've just tested your exact code and the returned string was correctly encoded:

http://www.mysite.com/?Value=This+%26+That

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

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