locked
Detection of target id RRS feed

  • Question

  • User-1894319593 posted
    How can I detect target id in an URL? If a web page links to one of my web pages like this: http://myWebSite/myWebPage#myTargetId I have no problems detecting HOST and PATH but what about the target id?
    Sunday, February 22, 2004 4:13 AM

All replies

  • User-1391363652 posted
    A regular expression will do the job. Something along the lines of: Match m = Regex.Match ("http://myWebSite/myWebPage#myTargetId", "\\#(.*)$"); string target = null; if (m.Success) target = m.Groups[1].Value;
    Sunday, February 22, 2004 6:24 PM
  • User883524816 posted
    You would want to use the Uri class's Fragment property. Uri uri= new Uri("http://site.com/page.aspx#Target"); Response.Write(uri.Fragment); // #Target For the currently request url, you could use the Request's Url property (which is a Uri) Response.Write(Request.Url.Fragment); HTH, Scott
    Tuesday, February 24, 2004 11:20 AM