9

Please help me to get query string value from the URL.

http://test.com/test.aspx#id=test

I tried to access with

Request.QueryString["id"]

Its getting null value.Please suggest how to access id from the url.

Thanks

PrateekSaluja
  • 14,680
  • 16
  • 54
  • 74

5 Answers5

11

I agree with everyone that the # should be a ?, but just FYI:

Note it isn't actually possible get the anchor off the URL, for example:

http://test.com/test.aspx#id=test

The problem is that # specified an anchor in the page, so the browser sees:

http://test.com/test.aspx

And then looks in the page for

<a id="test">Your anchor</a>

As this is client side you need to escape the # from the URL - you can't get it on the server because the browser's already stripped it off.

If you want the part after the # you have to copy it using Javascript before the request is sent to the server, and put the value in the querystring.

More info here c# get complete URL with "#"

Community
  • 1
  • 1
Ian G
  • 29,468
  • 21
  • 78
  • 92
8

A query string starts with a question mark ? not a hash #.

Try:

http://test.com/test.aspx?id=test 

Using a hash, you're asking to jump to a named anchor within the document, not providing a query string

Grhm
  • 6,726
  • 4
  • 40
  • 64
7

Your URL is not valid.

 http://test.com/test.aspx#id=test

refers to a bookmark named id=test.

You should use

http://test.com/test.aspx?id=test

And then Request.QueryString["id"] will work.

H H
  • 263,252
  • 30
  • 330
  • 514
4

If you would like to use it as hash tag you can use:

string value = Request.Url.ToString().Split('#')[1];

with this code, you will have your hash tag value.

Caner Akdeniz
  • 1,862
  • 14
  • 20
2

Isnt it supposed to be?

http://test.com/test.aspx?id=test 
craig1231
  • 3,769
  • 4
  • 31
  • 34