views:

63

answers:

3

In my application i have a url in the format

www.abc.com/mypage#yourId=ASDF2345.

How can i read back the value of yourId parameter from the Request object in asp.net , c# ?

If it would have been

www.abc.com/mypage?yourId=ASDF2345,

then i would have got this from the QueryString collection in the Request object. But there is a # before the yourId parameter and its not being provided by the QueryString collection.

+5  A: 

The hash you are referring to does not actually get sent to the server by the browser. It's client-side only, C# can't "see" it.

If you must have that value, you can get it with the document.location.hash property in Javascript and send it back to the server via AJAX.

This is made easier by jQuery BBQ or jQuery Address, which detect changes in the hash location, and can trigger events.

Matt Sherman
Thanks a lot. Appreciate it.
Bootcamp
+2  A: 

The part of the url that follows the # is called the "fragment identifier", and there is no way to access this information on the server. In fact, it's never even sent to the server -- the specification reserves the fragment identifier for the purpose of identifying a fragment of the document that is located by the rest of the url. The spec actually requires that the browser strip the fragment id from the url before sending the url in the HTTP request.

You can access the fragment id in the browser via javascript. The property is called document.location.hash.

Lee
+1  A: 

Read it on the client side using jQuery and transfer manually to server.

Example:

var url = "www.abc.com/mypage#yourId=ASDF2345";
var hash = url.substring(url.indexOf('#')); // '#yourId=ASDF2345'

Check

And remember that the user can change the hash as he/she wants. Check the hash before using it.

NAVEED