Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving anchor link in URL for ASP.NET

Tags:

I have a URL like so:

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

I am trying to see if there's the existence of the anchor tag along with getting its 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()); 

I 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 Stack Overflow's approach with a permalink... :D

like image 554
TimLeung Avatar asked Apr 21 '09 19:04

TimLeung


People also ask

What is the URL for an anchor?

The hypertext reference, or href , attribute is used to specify a target or destination for the anchor element. It is most commonly used to define a URL where the anchor element should link to. In this example, the <a href="http://example.com">anchored text</a> links to the URL <em>www.example.com</em>.

What is an anchor in asp net?

The Anchor Tag Helper enhances the standard HTML anchor ( <a ... > </a> ) tag by adding new attributes. By convention, the attribute names are prefixed with asp- . The rendered anchor element's href attribute value is determined by the values of the asp- attributes.

What is anchor in web?

An anchor is an HTML tag that identifies a link to text or an image on the same page or to another specific location. An anchor can be used in two ways: By using the “href” attribute to create a link to another page. By using the "name" attribute to create a bookmark within a page.


1 Answers

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

This is a client-side flag to tell the browser to move to a specific place within the page.

You can use some JavaScript code 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: Retrieving the anchor value from a URL

like image 78
Eoin Campbell Avatar answered Sep 29 '22 23:09

Eoin Campbell