tags:

views:

2601

answers:

2

I have an url like so:

http://localhost/place/663828/bangkok-paradise-restaurant-toronto#r306040

I am trying to see if theres the existence of the anchor tag along with getting it's value to do some code logic in the code behind.

I have been trying to use the Page.Request, but none of the properties show the anchor link portion of the url.

For example:

Response.Write(this.Page.Request.RawUrl.ToString());

Pretty much tried the combinations/properties on this page: http://www.west-wind.com/weblog/posts/269.aspx

Just to finalize this topic:

I copied Stackoverflow's approach with permalink... :D

+11  A: 

It's not possible to retrieve the #anchor from the server side in ASP.NET

This is a clientside flag to tell the browser to move to a specific place in the page.

You can use some Javascript in the body onLoad event to check for an anchor and send it back to the server using ajax.

var anchorValue;
var url = document.location;
var strippedUrl = url.toString().split("#");
if(strippedUrl.Length > 1)
anchorvalue = strippedUrl[1];

ref: http://www.wacdesigns.com/2008/01/16/retrieving-anchor-value-from-url/

Eoin Campbell
+9  A: 

Being more explicit, the anchor tag is never sent as part of the HTTP request by any browser, it is only interpreted locally within the browser. Neither ASP.NET nor any other web-server technology, Microsoft or otherwise will see the anchor on that request.

RFC 1808
Section 2.4.1 - "Note that the fragment identifier is not considered part of the URL."

As others have suggested the nearest you could get would be using client-side to read browser window location.

stephbu
Well, you're not completely right.. See: [http://www.php.net/manual/en/function.parse-url.php]
Miky Dinescu
Miky just because someone wrote a piece of code to parse anchors out of URLs - still doesn't mean it is sent by any browser over the wire.Try it - use your favourite network monitor of choice to watch the wire. You won't see any anchor in the HTTP request.
stephbu