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

5 Answers 5

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 "#"

Sign up to request clarification or add additional context in comments.

Comments

9

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

Comments

8

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.

2 Comments

Its api call so i can't do anything.
I see you have come a long way @HenkHolterman. With 193K reputation and in the top 0.05% or SO you probably now know what an API call is haha.
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.

Comments

2

Isnt it supposed to be?

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.