65.9K
CodeProject is changing. Read more.
Home

Special Character # in URL Query String

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

Mar 27, 2012

CPOL
viewsIcon

55647

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:

<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!