locked
Getting URL without Query String RRS feed

  • Question

  • User1165667961 posted
    Is there an easy way to get the URL portion without the query string of a given URL? E.g. http://www.abc.com/?a=b&c=d --> http://www.abc.com/
    Tuesday, August 31, 2004 5:43 PM

All replies

  • User1779069737 posted
    Stanley, The pattern could be more precise, but try: Dim noQuery As String = Regex.Match(Page.Request.Url.ToString, "^(\S+)(\?)(\S+)$").Groups(1).ToString() HTH, cjmaxey
    Tuesday, August 31, 2004 6:27 PM
  • User645477409 posted
    string stringUri = "http://www.abc.com/?a=b&c=d"; Uri uri = new Uri(stringUri); string query = uri.Query; string url = stringUri.Substring(0, stringUri.Length - query.Length);
    Tuesday, August 31, 2004 7:30 PM
  • User309510958 posted
    Hi, I believe you could do something like: Response.Write("
    " + Request.ServerVariables["HTTP_HOST"] + Request.ServerVariables["SCRIPT_NAME"] + "
    ");
    -Mike
    Tuesday, August 31, 2004 7:33 PM
  • User102712579 posted
    Try Request.Url.GetLeftPart(UriPartial.Path) Harold Hoffman
    Tuesday, August 31, 2004 9:00 PM
  • User1165667961 posted
    That works nicely Harold, thanks.
    Thursday, September 2, 2004 10:39 PM
  • User-1987227794 posted

    i too was stuck up with the same problem, thanks Harold for the tip. 

    Thursday, August 21, 2008 6:39 AM
  • User-953450191 posted

    Thanks Harold. This helped me too. Laughing

    Friday, July 23, 2010 10:35 PM
  • User-1085172183 posted

    you can simple do it by regex but programmatically i used


    <title>Snippet</title>

      Uri uri = new Uri("http://www.google.com/q=439489");
                string url = uri.Host.ToString();
    Saturday, July 24, 2010 1:21 AM
  • User505764882 posted

    Thanks Harold, That worked beautifully.

    Monday, January 17, 2011 3:31 AM
  • User-2093610467 posted

    Thanks Harold,

    Very helpful...

    Wednesday, May 2, 2012 5:58 AM