Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Parameter

Special Character # in URL Query String

0.00/5 (No votes)
27 Mar 2012CPOL 55.6K  
Special Character # in URL Query String creates problem

Normally special characters ‘ and “ will cause issues when passed in a URL during submit. For example,

http://www.example.com?name=test&ID=123&comments=special’Ch"aracters; 

The URL will be cut and only the values "http://www.example.com?name=test&ID=123&comments=special" will be taken. 

But # also creates an issue. How does it actually create a problem? By URL specifications, "#" is a reference to the start of the current document.

For example, an author might create a table of contents whose entries link to header elements H2, H3, etc., in the same document. Using the A element to create destination anchors, we would write:

HTML
<H1>Table of Contents</H1>
<P><A href= "#section1" >Introduction</A><BR>
<A href="#section2" >Block 1</A><BR>
...the document body...
<H2><A name="section1" >Introduction</A></H2>
...section 1… 
<H2><A name="section2" >Bloxk 1</A></H2>

...section 1...

Thus, the character "#" should be excluded in that are passed in the URL because it is used to delimit a URI from a fragment identifier in URI. If we pass a field with ‘#’, the fields that are sent in the URL after the field with ‘ # ‘ will be set to null.

http://strata.nbcuni.ge.com?name=test&ID=1#23&comments=special

Here ID will become 1 and comments will become null.

Hope this helps!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)