Special Characters in Query String

S

SMG - Idealake

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?

P.S. Hi Juan T. Llibre,
if you have cracked that things, can you mail me to (e-mail address removed)
id please.

Thanks and best regards,
Shailesh Gajare
 
K

Kevin Spencer

Use Server.UrlEncode(string)

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.
 
P

Patrice

Give this a try. It shouldn't be a big change as QueryString decodes this
automatically for you. You'll have just to encode the values using
Server.URLEncode.

I don't think you can do better as the system has no way to know
automatically that the & you have is part of the value instead of being
taken as a separator (you have to tell this by encoding the value)...

You could try a test such as :
Response.Write (Request.QueryString("MyVar"))
Response.Write("<a href="""?MyVar=" &
Server.URLEncode("MyValue&/*WithSomeCharacters") & """>Test</a>")

Patrice
 
J

Juan T. Llibre

re:
P.S. Hi Juan T. Llibre,
if you have cracked that things, can you mail me to (e-mail address removed) id please.

SMG,

What Jorg and I are working on regards file encoding.
Your problem relates to query string encoding.

The answer to the problem Jorg and I are working on will not
help you solve the problem you're having with query string encoding.

In any case, there will be at least a 2 week delay, since I'm going on an
11 day trip starting today and won't be able to work on this in the meantime.

Jorg and I will post the resolution to the file encoding problem
as soon as we finish the analysis ( which is fairly complex... ).






SMG - Idealake said:
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?

P.S. Hi Juan T. Llibre,
if you have cracked that things, can you mail me to (e-mail address removed)
id please.

Thanks and best regards,
Shailesh Gajare
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top