开发者

I have a url in the format www.abc.com/mypage#yourId=ASDF2345. How to read the value of yourid using c#

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.c开发者_高级运维om/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.


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜