问题描述
我有一个问题,如果我通过包含 +
在查询字符串,并尝试读取它一个字符串,它得到相同的字符串,但用空替换+焦炭结果
例如,如果我传似查询../ Page.aspx?数据= SDF1 + SDF
然后在页面加载我读数据
按数据=的Request.QueryString [数据]
它会得到如下数据=SDF1自卫队
结果
我用 +
..
I have a problem that if I pass a string that contain +
in a query string and try to read it , it get the same string but by replacing + with empty char
For example if i pass query like ../Page.aspx?data=sdf1+sdf
then in page load I read data
by data = Request.QueryString["data"]
it will get as below data ="sdf1 sdf"
I solve the problem by replacing any empty char with +
..
但有没有造成任何问题吗?并通过与+更换空字符我的解决方案是在所有情况下的最佳解决方案?
推荐答案
由于 +
是URL连接的空间,
。如果您想preseve在你的价值的加号,您将需要给url EN code是:
Because +
is the url encoded representation of space " "
. If you want to preseve the plus sign in your value you will need to url encode it:
"/Page.aspx?data=" + HttpUtility.UrlEncode("sdf1+sdf")
这将产生:
/Page.aspx?data=sdf1%2bsdf
现在当你读的Request.QueryString [数据]
你会得到你所期望的。
Now when you read Request.QueryString["data"]
you will get what you expect.
这篇关于为什么用的Request.QueryString在某些情况下,空字符替换+?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!