Using ASP.NET MVC3, the url http://localhost:22713/tests#123456
with the following code:
Your user agent: @Request.UserAgent<br />
Url: @Request.Url.AbsoluteUri<br />
Url fragment: @Request.Url.Fragment<br />
returns:
Your user agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16
Url: http://localhost:22713/tests
Url fragment:
Why is fragment always empty? I need to be able to parse this info on the server side.
A fragment is an internal page reference, sometimes called a named anchor. It usually appears at the end of a URL and begins with a hash (#) character followed by an identifier. It refers to a section within a web page. In HTML documents, the browser looks for an anchor tag with a name attribute matching the fragment.
A hash sign (#) in a URL is referred to as a fragment. Historically, URL fragments have been used to automatically set the browser's scroll position to a predefined location in the web page. In that sense, if a URL refers to a document, then the fragment refers to a specific subsection of that document.
Fragment identifiers are not sent to the server. The hash fragment is used by the browser to link to elements within the same page.
A URL cannot have more than one fragment. URL parameters are passed in key-value pairs. URL fragments comprise just a string of text after the hash (#).
The fragment (everything after the # in a url) doesn't get passed to the server. So the Fragment
property will always be empty when you attempt to get it from a request.
The Fragment
property is typically only used when constructing URLs.
There's no easy way to get the fragment on the server. Typically you would have to use javascript to retrieve the fragment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With