2

Anyone know if it's possible to access the name of a jump link in c# code?

I'm doing some url Rewriting stuff and I'm thinking I might not be able to see that part of the URL.

So basically, my URL looks a little something like this:

http://www.mysite.com/Terms.aspx#Term1

And I want to access "Term1". I can't see it in the ServerVariables...

Any ideas?!?!?

THANKS!

lispmachine
  • 4,407
  • 1
  • 22
  • 31
Ev.
  • 7,109
  • 14
  • 53
  • 87

2 Answers2

4

The hash character is meant for client side navigation. Anything after the # is not submitted to the server.

From the wikipedia article:

The fragment identifier functions differently than the rest of the URI: namely, its processing is exclusively client-side with no participation from the server. When an agent (such as a Web browser) requests a resource from a Web server, the agent sends the URI to the server, but does not send the fragment.

Its technical name is Fragment Identifier

Yona
  • 9,392
  • 4
  • 33
  • 42
2

Perhaps System.Uri.Fragment? Or what is it you don't see?

Pontus Gagge
  • 17,166
  • 1
  • 38
  • 51
  • 3
    System.Uri.Fragment will only contain the fragment if the url contains one, when an HTTP request is made the fragment part is not submitted to the server, that's why this won't work – Yona May 05 '09 at 14:40
  • +1 Initialize a Uri object and you should be able to access the fragment. – Pat May 05 '09 at 14:41
  • 1
    No, he wont. The fragment is never submitted to the server by the web browser. The fragment property will only show the fragment if it was initialized by a url that includes a fragment. – Yona May 05 '09 at 14:45
  • Great! Thanks man. That's really close to what I'm after. So if I hardcode: System.Uri uri = new Uri("http://www.mysite.com/Terms.aspx#Term1"); then go uri.Fragment I get "#Term1" which is exactly what I'm after. The problem is, the URL should be the current location of the page. How can I programatically get that URI, including what is after the hash character. – Ev. May 05 '09 at 14:48
  • @Y Low: thanks a lot - sounds like you know what I'm talking about here. If the fragment is not submitted to the server, I'll never be able to access it. Can you (or anyone) confirm this for me? – Ev. May 05 '09 at 14:49
  • 1) You wont get '#Term1', You'll get 'Term1' (the # is not part of the fragment) 2) This will not work if the url comes from a client request (since client requests never submit the fragment) – Yona May 05 '09 at 14:51
  • Check the RFC specification or the link I provided in the answer below – Yona May 05 '09 at 14:51