问题
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