Get url without querystring

前端 未结 18 1990
后悔当初
后悔当初 2020-11-28 21:24

I have a URL like this:

http://www.example.com/mypage.aspx?myvalue1=hello&myvalue2=goodbye

I want to get http://www.example.com/mypage

相关标签:
18条回答
  • 2020-11-28 21:32
    this.Request.RawUrl.Substring(0, this.Request.RawUrl.IndexOf('?'))
    
    0 讨论(0)
  • 2020-11-28 21:34

    Good answer also found here source of answer

    Request.Url.GetLeftPart(UriPartial.Path)
    
    0 讨论(0)
  • 2020-11-28 21:35
    var canonicallink = Request.Url.Scheme + "://" + Request.Url.Authority + Request.Url.AbsolutePath.ToString();
    
    0 讨论(0)
  • 2020-11-28 21:36

    My way:

    new UriBuilder(url) { Query = string.Empty }.ToString()
    

    or

    new UriBuilder(url) { Query = string.Empty }.Uri
    
    0 讨论(0)
  • 2020-11-28 21:36

    Try this:

    urlString=Request.RawUrl.ToString.Substring(0, Request.RawUrl.ToString.IndexOf("?"))
    

    from this: http://www.example.com/mypage.aspx?myvalue1=hello&myvalue2=goodbye you'll get this: mypage.aspx

    0 讨论(0)
  • 2020-11-28 21:37
    Request.RawUrl.Split('?')[0]
    

    Just for url name only !!

    0 讨论(0)
提交回复
热议问题