C#中带有特殊字符的查询字符串问题 [英] Querystring Issue on C# with special characters
问题描述
我遇到了一个非常奇怪的问题,在我的querystirng中,"++"作为文本的一部分.但是,当我将查询搅拌值分配给字符串++时,它将变成两个空格.我该如何确切地获取作为查询字符串传递的内容?
I came across a very weird issue where in my querystirng had "++" as part of the text. but when i assign the query stirng value to a string ++ will become two spaces. How do i get exactly what is being passed as querystring?
我观察到querystirng集合具有"++",但是当我执行Request.QueryString ["search"].ToString()"++"时,我在即时窗口中进行了检查.
I observed that the querystirng collection had "++" but when I do Request.QueryString["search"].ToString() "++" gone, I checked in Immediate window.
我使用C#2.0
URL:/default.aspx?search=test ++
URL: /default.aspx?search=test++
string t = Request.QueryString["search"].ToString();
推荐答案
查询字符串中的加号会转换为空格.如果要使用实际的加号而不是空格,请改用%2B
.
A plus sign in a query string translates to a space. If you want an actual plus sign rather than a space, use %2B
instead.
/default.aspx?search=test%2B%2B
如果您使用代码执行此操作,则应使用 UrlEncode
对查询字符串的这一部分进行编码.
If you're doing this in code, then you should be using UrlEncode
to encode this portion of the query string.
这篇关于C#中带有特殊字符的查询字符串问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!