Click here to Skip to main content
15,614,665 members
Articles / Parameter
Posted 27 Mar 2012

Tagged as


2 bookmarked

Special Character # in URL Query String

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
27 Mar 2012CPOL
Special Character # in URL Query String creates problem

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

The URL will be cut and only the values "" 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.

Here ID will become 1 and comments will become null.

Hope this helps!


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

Comments and Discussions

QuestionHow to pass special character in query string. Pin
Member 1398146125-May-20 22:10
Member 1398146125-May-20 22:10 
QuestionQuestion Pin
Laserson27-Mar-12 17:18
Laserson27-Mar-12 17:18 
What is the reason of using such special characters in the URL? (except of anchors)

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.