473,569 Members | 2,844 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Special Characters in Query String

SMG
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
Nov 19 '05 #1
20 9350
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.Url Encode(strQuery , System.Text.Enc oding.Default)

Kim :o)
Nov 19 '05 #2
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.Url Encode(strQuery ,
System.Text.Enc oding.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.d e
Nov 19 '05 #3
Joerg Jooss wrote:
strQuery = HttpUtility.Url Encode(strQuery ,
System.Text.E ncoding.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.Enc oding.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)
Nov 19 '05 #4
Kim Bach Petersen wrote:
Joerg Jooss wrote:
strQuery = HttpUtility.Url Encode(strQuery ,
System.Text.Enc oding.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.Enc oding.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.


You're confusing the need to use Windows-1252 with the need to use
Encoding.Defaul t.

For Western European and US Windows OSs Encoding.Defaul t will be an
instance of Windows-1252, but for other configurations it won't.
Relying on platform or installation dependent default values impairs
your application's portability.

Cheers,
--
http://www.joergjooss.de
mailto:ne****** **@joergjooss.d e
Nov 19 '05 #5
re:
Obviously UTF-8 is to be preferred
Why ?

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
=============== =======

"Kim Bach Petersen" <in*******@spam .dk> wrote in message
news:eP******** ********@TK2MSF TNGP12.phx.gbl. .. Joerg Jooss wrote:
strQuery = HttpUtility.Url Encode(strQuery ,
System.Text. Encoding.Defaul t)


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.Enc oding.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)

Nov 19 '05 #6
Juan T. Llibre wrote:
re:
Obviously UTF-8 is to be preferred


Why ?


Globalization -- assuming you serve mostly content based on Western
European languages but don't want to get stuck with any 8 bit encodings
like ISO-8859-x.

Cheers,
--
http://www.joergjooss.de
mailto:ne****** **@joergjooss.d e
Nov 19 '05 #7
re:
assuming you serve mostly content based on Western European languages
That's a mighty big assumption to make, don't you think ?

Even so, using UTF-8, I haven't found a way
to display characters in the high-ascii 128-255 range,
which several Western European languages require.

I've been able to do that by using iso-8859-1.

Can you post a sample, using utf-8,
which displays characters in the high-ascii 128-255 range ?

I'd be a bit more liable to believe you if you did.

Specifically, if you could show me how to display the
characters ñ, Ñ, ¡, ¿, á, é, í, ó, and ú with utf-8, I'd be grateful.

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
=============== =======

"Joerg Jooss" <ne********@joe rgjooss.de> wrote in message
news:xn******** ********@msnews .microsoft.com. .. Juan T. Llibre wrote:
re:
> Obviously UTF-8 is to be preferred


Why ?


Globalization -- assuming you serve mostly content based on Western
European languages but don't want to get stuck with any 8 bit encodings
like ISO-8859-x.

Cheers,
http://www.joergjooss.de

Nov 19 '05 #8
Juan T. Llibre wrote:
re:
assuming you serve mostly content based on Western European
languages
That's a mighty big assumption to make, don't you think ?


No, not all. It just doesn't make sense to use UTF-8 from a bandwidth
perspective once you need to serve a lot of content in on other
languages or scripts, as one character may require up to six bytes.
Even so, using UTF-8, I haven't found a way
to display characters in the high-ascii 128-255 range,
which several Western European languages require.
Then you've been doing something wrong. Let me quote the Unicode
standard document:

"The Unicode Standard provides 1,114,112 code points, most of which are
available for encoding of characters. The majority of the common
characters used in the major languages of the world are encoded in the
first 65,536 code points, also known as the Basic Multilingual Plane
(BMP). The overall capacity for more than a million characters is more
than sufficient for all known character encoding requirements,
including full coverage of all minority and historic scripts of the
world."

There's no civilized 8 bit encoding that cannot be replaced by Unicode
;-)
I've been able to do that by using iso-8859-1.
If you can display your characters with ISO-8859-1, you have
accidentally or willingly switched the response encoding.
Can you post a sample, using utf-8,
which displays characters in the high-ascii 128-255 range ?
Let's avoid the errors of the past -- there's no such thing as Hi ASCII
or 8 bit ASCII. US-ASCII and all its localized clones (ISO-646-xx) are
7 bit. ISO-8859-x, Windows-125x are built "on top of" US-ASCII.

If you want to see UTF-8 in real live, feel free to visit my homepage
which is running dasBlog and serves content in UTF-8.
I'd be a bit more liable to believe you if you did.

Specifically, if you could show me how to display the
characters ñ, Ñ, ¡, ¿, á, é, í, ó, and ú with utf-8, I'd be grateful.


OK, do the following:

1. Create a new WebForm in a new ASP.NET project. Make sure that your
web.config's <globalizatio n/> looks like this:
<globalizatio n
requestEncoding ="utf-8"
responseEncodin g="utf-8" />

2. Add a Label control to the WebForm, call it "label" and set its text
in the property control to the empty string.

3. Implement the Page_Load method like this:
this.label.Text = "ñ, Ñ, ¡, ¿, á, é, í, ó, and ú";

4. Run the WebForm -- it should display the text given above.

And that's pretty much it.

See, once you have the characters in a string object and the page is
not rendered correctly, one of the following errors may have occurred:

-- Your browser is configured to use a fixed encoding, which does not
match andf is not compatible with the real encoding (like ISO-8859-1
vs. UTF-8 for non-ASCII content). This will lead to weird or missing
characters in web pages (responses).

-- Neither the HTTP response nor the HTML source specify the character
encoding. In that case, the browser must guess, and of course it can
guess wrong. This should never happen with any decent web application
technology. ASP.NET for example sends a proper
Content-Type: text/html; charset=utf-8
HTTP header.

Then there's the case that you have a build-time error. In the example
given above, I've hardcoded the string in my source file. The ASP.NET
page processor needs to know the source file's encoding to decode these
characters correctly -- that's what the fileEncoding attribute of the
<globalizatio n/> element does. If you'd changed that attribute to an
incompatible one or one that cannot represent a given character, that
particular character would be already missing in the resulting string
object. This isn't usually a problem as display text belongs into
satellite assemblies anyway, but for simple applications this needs to
be kept in mind.

I hope this helps.

Cheers,
--
http://www.joergjooss.de
mailto:ne****** **@joergjooss.d e
Nov 19 '05 #9
Hi, Joerg.

Take a look at the result :
http://asp.net.do/test/utf-8.aspx
( Browsing it with IE6 set to use utf-8 results in the same.)

Now, look at the same code, using iso-8859-1 :
http://asp.net.do/test3/iso-8859-1.aspx
( Browsing with IE6 set to "Auto-select",
results in Western European getting selected.)

I've had numerous problems with utf-8, all of which result
in common characters in spanish not geting displayed.

Using iso-8859-1 gets rid of the problems.

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
=============== =======

"Joerg Jooss" <ne********@joe rgjooss.de> wrote in message
news:xn******** ********@msnews .microsoft.com. ..
Juan T. Llibre wrote:
re:
> assuming you serve mostly content based on Western European
> languages


That's a mighty big assumption to make, don't you think ?


No, not all. It just doesn't make sense to use UTF-8 from a bandwidth
perspective once you need to serve a lot of content in on other
languages or scripts, as one character may require up to six bytes.
Even so, using UTF-8, I haven't found a way
to display characters in the high-ascii 128-255 range,
which several Western European languages require.


Then you've been doing something wrong. Let me quote the Unicode
standard document:

"The Unicode Standard provides 1,114,112 code points, most of which are
available for encoding of characters. The majority of the common
characters used in the major languages of the world are encoded in the
first 65,536 code points, also known as the Basic Multilingual Plane
(BMP). The overall capacity for more than a million characters is more
than sufficient for all known character encoding requirements,
including full coverage of all minority and historic scripts of the
world."

There's no civilized 8 bit encoding that cannot be replaced by Unicode
;-)
I've been able to do that by using iso-8859-1.


If you can display your characters with ISO-8859-1, you have
accidentally or willingly switched the response encoding.
Can you post a sample, using utf-8,
which displays characters in the high-ascii 128-255 range ?


Let's avoid the errors of the past -- there's no such thing as Hi ASCII
or 8 bit ASCII. US-ASCII and all its localized clones (ISO-646-xx) are
7 bit. ISO-8859-x, Windows-125x are built "on top of" US-ASCII.

If you want to see UTF-8 in real live, feel free to visit my homepage
which is running dasBlog and serves content in UTF-8.
I'd be a bit more liable to believe you if you did.

Specifically, if you could show me how to display the
characters ñ, Ñ, ¡, ¿, á, é, í, ó, and ú with utf-8, I'd be grateful.


OK, do the following:

1. Create a new WebForm in a new ASP.NET project. Make sure that your
web.config's <globalizatio n/> looks like this:
<globalizatio n
requestEncoding ="utf-8"
responseEncodin g="utf-8" />

2. Add a Label control to the WebForm, call it "label" and set its text
in the property control to the empty string.

3. Implement the Page_Load method like this:
this.label.Text = "ñ, Ñ, ¡, ¿, á, é, í, ó, and ú";

4. Run the WebForm -- it should display the text given above.

And that's pretty much it.

See, once you have the characters in a string object and the page is
not rendered correctly, one of the following errors may have occurred:

-- Your browser is configured to use a fixed encoding, which does not
match andf is not compatible with the real encoding (like ISO-8859-1
vs. UTF-8 for non-ASCII content). This will lead to weird or missing
characters in web pages (responses).

-- Neither the HTTP response nor the HTML source specify the character
encoding. In that case, the browser must guess, and of course it can
guess wrong. This should never happen with any decent web application
technology. ASP.NET for example sends a proper
Content-Type: text/html; charset=utf-8
HTTP header.

Then there's the case that you have a build-time error. In the example
given above, I've hardcoded the string in my source file. The ASP.NET
page processor needs to know the source file's encoding to decode these
characters correctly -- that's what the fileEncoding attribute of the
<globalizatio n/> element does. If you'd changed that attribute to an
incompatible one or one that cannot represent a given character, that
particular character would be already missing in the resulting string
object. This isn't usually a problem as display text belongs into
satellite assemblies anyway, but for simple applications this needs to
be kept in mind.

I hope this helps.

Cheers,
--
http://www.joergjooss.de
mailto:ne****** **@joergjooss.d e

Nov 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
7300
by: mr h q | last post by:
Hi all, i want to replace $ to \$ so linux can work with paths and filenames that contain $. I wrote the following code for(string::size_type i = s.find(exist, 0); i != string::npos; i = s.find(foo, i)) { s.replace(i, foo.size(), bar);
4
5251
by: Ewok | last post by:
let me just say. it's not by choice but im dealing with a .net web app (top down approach with VB and a MySQL database) sigh..... Anyhow, I've just about got all the kinks worked out but I am having trouble preserving data as it gets entered into the database. Primarily, quotes and special characters. Spcifically, I noticed it stripped...
2
3425
by: Jorge Ribeiro | last post by:
hell I've an ASP.Net page that, by the action of one submit button, redirects from one Web form to another passin in the query string one value that will be processed in the later web form So far so good My question derives from the fact that, because I'm using portuguese keyboard layout and language, some special characters cannot be...
3
651
by: SMG - Idealake | last post by:
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...
5
8605
by: Sakharam Phapale | last post by:
Hi All, I am using an API function, which takes file path as an input. When file path contains special characters (@,#,$,%,&,^, etc), API function gives an error as "Unable to open input file". Same file path containing special characters works fine in one machine, but doesn't work in other. I am using following API function to get short...
17
30642
by: Carl Mercier | last post by:
Hi, Is it possible to use special characters like \n or \t in a VB.NET string, just like in C#? My guess is NO, but maybe there's something I don't know. If it's not possible, does anybody know of a VB.NET function (somebody must have coded this already) that will interpret strings containings those special characters, and handle them...
8
3652
by: david.lindsay.green | last post by:
Hello all, I am quite new a web scripting and making web pages in general and I have stumbled across a problem I have as yet been unable to solve. I am trying to take the contents of a textarea box and save it to a file. This step is not to hard however the contents of the textarea is mostly latex source so it contains just about every special...
6
3864
by: TheRealDan | last post by:
Hi all. I'm having a problem with a special characters. I have php script that reads from an xml file and writes to a mysql db. It's a script called phptunest that I found on the net, although the original website for the author appears to be gone. It works really nicely except when it hits special characters. Everything from a sp char...
0
1702
by: dearsaran | last post by:
Hi, I Want a function written for finding the special characters in a emailid.. Suppose, i've a column email in a table and inserting a emailid with any of the special characters then if i compile the funtion then it should show the wrong emailid's Example: If a emailid is dear#$saran@gmail!#$%.com then 1st it should check any special char...
5
11149
by: Sobin Thomas | last post by:
Hi All, I want to pass a string that contains many special characters (: \ . _ etc) to another page in my website through query string. In my project I have a Gridview control ,in which there is a hyperlink field.The Gridview 's datasource is set as a database table at runtime.The hyperlink filed's DataNavigateUrlFields is set to...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7668
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6281
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5218
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.