1

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

Juri
  • 32,424
  • 20
  • 102
  • 136
Andreas
  • 187
  • 5
  • 14
  • Why do you need such functionality? Maybe there's an alternative way of solving your problem. – Juri Aug 24 '09 at 12:38
  • Its because creator of the page has used querystrings to pass passwords, and thus disabling a password containing #, stupid, I know – Andreas Aug 24 '09 at 12:40
  • You should avoid passing passwords in query strings, as doing so allows you to log in from a query string without a post. Some browser add-ins (such as Google web accelerator) can hit these thinking that they are navigation, rather than actions. As a general rule GETs should just display stuff, anything that changes data or state should be POST – Keith Aug 24 '09 at 12:43
  • Is 'disabling a password containing #' the problem? I'm sure you could escape/encode characters like # in a password to get around that. – waterlooalex Aug 24 '09 at 13:26

3 Answers3

8

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.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005
6

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.

Keith
  • 150,284
  • 78
  • 298
  • 434
0

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.