c# get complete URL with “#”

I have run into a trivial(?) problem when trying to get the whole URL of a c# page.

The url contains the “#”-link ref char. And i would like that to when I grab the URL

Eg. http://localhost/site/page.aspx?var=1&var=2#link

I have tried Request.URL, Request.Querystring etc, it only returns up to the “#”-char.

Is there any way to grab even the last part?

Thanks in advance

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

That is not possible using server code only. The part after the # is not sent in the request at all, it never leaves the browser.

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.

Method 2

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

http://localhost/site/page.aspx?var=1&var=2

And then looks in the page for

<a name="link">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.

Method 3

Are you sure that the stuff after the # isn’t sent to the server. I’m pretty sure i made a test with an ajax-app some years ago where the url could be copied and sent to people without javascript by only modifiying the stuff after the # in the url when browsing around with javascript enabled.

That was in PHP and the browser was probably IE6.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x