查询字符串中的特殊字符 [英] Special Characters in Query String
问题描述
大家好,
我创建了一个工作正常且即将发布的应用程序,现在突然我的mgmt说有可能是Scrip ID( a
特定id而非prim键)可能有特殊字符,如''&,*,),(或
/''
>
这个数据(字段/键)我将此值作为查询字符串传递。例如
要传递的
值:ABC
http://localhost/myProj/abc.aspx?ScripID = ABC
这样可以正常工作,
但是当我有像[ABC& D]这样的特殊字符时,检索到的值是
错误它只是检索ABC和不完整的身份证[ABC& D]
要传递的
值:ABC& D
http://localhost/myProj/abc.aspx?ScripID = ABC& D
如何克服这个问题, 我知道 我可以这样做,就像我们有20%的空间和
一样明智的&会有一些东西,但这将是我的应用程序的一个重大变化,我可以在web.config或aspx
页面的某一端做到这一点吗?
问候,
Shailesh Gajare
SMG写道:
但是当我有像[ABC& D]这样的特殊字符时,检索到的值是错误的,它只是检索ABC而不是完整的ID [ABC& D]
值通过:ABC& D
http:// localhost /myProj/abc.aspx?ScripID=ABC&D
我如何克服这一点,我知道我可以做到就像我们有20%的空间和
一样明智for&会有一些东西,但这将是我的应用程序的一个重大改变,我可以在web.config或aspx
页面的某一端做到这一点吗?
你必须将你传递的字符串作为查询字符串UrlEncode:
strQuery = HttpUtility.UrlEncode(strQuery,System.Text.Encoding.Default)
Kim:o)
Kim Bach Petersen写道:
SMG写道:
但是当我有像[ABC& D]这样的特殊字符时,检索到的值是错误的,它只是检索ABC而不是完整的ID [ABC& D]
值传递:ABC& D
http:/ /localhost/myProj/abc.aspx?ScripID=ABC&D
如何克服这个问题,我知道我可以做到就像我们有%20的空间和和...一样明智会有一些东西,但这将是我的应用程序的一个重大改变,我可以在一端做一些
在web.config或aspx页面中吗?
你必须将你传递的字符串UrlEncode作为查询字符串:
strQuery = HttpUtility.UrlEncode(strQuery,
System.Text.Encoding.Default)
我建议使用比某些Windows特定的网络友好编码
默认,例如ISO-8859-1或UTF-8。
干杯,
-
http://www.joergjooss.de
mailto:ne ******** @ joergjooss.de
Joerg Jooss写道:
strQuery = HttpUtility.UrlEncode(strQuery,
System.Text.Encoding.Default)
我建议使用比某些Windows特定的更友好的网络编码
默认,例如ISO-8859-1或UTF-8。
显然UTF-8是首选,在大多数情况下这是实际的
System.Text.Encoding.Default返回的默认值。
不过,根据我的经验,人们需要使用默认值而不是
明确选择UTF- 8如果应用程序要在_any_ webhotel
上运行而不会遇到编码不匹配问题,至少在查询字符串中。
Kim:o)
Hi All,
I have created an application which is working fine and is in about to
launch, now suddenly my mgmt says there are chances that Scrip ID( a
particular id and not prim key) may have special characters like ''&,*,),( or
/''
This data(field/key) I am passing this value as a querystring. e.g.
value to be passed : ABC
http://localhost/myProj/abc.aspx?ScripID=ABC
this works fine,
But when I have special characters like [ABC&D] then the value retrieved is
wrong it just retrieves ABC and not complete ID [ABC&D]
value to be passed : ABC&D
http://localhost/myProj/abc.aspx?ScripID=ABC&D
how do I overcome this, I know I can do it like we have %20 for space and
like wise for & there will be something, but this will be a major change to
my application, can I do this at one end some where in web.config or in aspx
page?
Regards,
Shailesh Gajare
SMG wrote:
But when I have special characters like [ABC&D] then the value retrieved is
wrong it just retrieves ABC and not complete ID [ABC&D]
value to be passed : ABC&D
http://localhost/myProj/abc.aspx?ScripID=ABC&D
how do I overcome this, I know I can do it like we have %20 for space and
like wise for & there will be something, but this will be a major change to
my application, can I do this at one end some where in web.config or in aspx
page?
You have to UrlEncode the string you are passing as a querystring:
strQuery = HttpUtility.UrlEncode(strQuery, System.Text.Encoding.Default)
Kim :o)
Kim Bach Petersen wrote:
SMG wrote:But when I have special characters like [ABC&D] then the value
retrieved is wrong it just retrieves ABC and not complete ID [ABC&D]
value to be passed : ABC&D
http://localhost/myProj/abc.aspx?ScripID=ABC&D
how do I overcome this, I know I can do it like we have %20 for
space and like wise for & there will be something, but this will be
a major change to my application, can I do this at one end some
where in web.config or in aspx page?
You have to UrlEncode the string you are passing as a querystring:
strQuery = HttpUtility.UrlEncode(strQuery,
System.Text.Encoding.Default)
I suggest using a more web-friendly encoding than some Windows specific
default, e.g. ISO-8859-1 or UTF-8.
Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Joerg Jooss wrote:
strQuery = HttpUtility.UrlEncode(strQuery,
System.Text.Encoding.Default)
I suggest using a more web-friendly encoding than some Windows specific
default, e.g. ISO-8859-1 or UTF-8.
Obviously UTF-8 is to be preferred and in most cases this is the actual
default value returned by System.Text.Encoding.Default.
Still, in my experience, one needs to use the default rather than
explicitly choosing UTF-8 if the application is to run on _any_ webhotel
without encountering encoding mismatch problems, at least with querystrings.
Kim :o)
这篇关于查询字符串中的特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!