why Request.QueryString replace + with empty char in some cases?

蹲街弑〆低调 提交于 2020-01-04 06:30:03

问题


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 + ..

But Is there any problem that cause that ? and Is my solution by replacing empty char with + is the best solution in all cases ?


回答1:


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")

which will produce:

/Page.aspx?data=sdf1%2bsdf

Now when you read Request.QueryString["data"] you will get what you expect.



来源:https://stackoverflow.com/questions/3356829/why-request-querystring-replace-with-empty-char-in-some-cases

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!