Get url parts without host

后端 未结 4 2007
遥遥无期
遥遥无期 2020-12-10 10:14

I have a url like this :

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

I want to get mypage.aspx?myvalue1=hello&myvalue2=goodb

相关标签:
4条回答
  • 2020-12-10 10:52
    var uri = new Uri("http://www.somesite.com/mypage.aspx?myvalue1=hello&myvalue2=goodbye");
    
    string pathOnly = uri.LocalPath;        // "/mypage.aspx"
    string queryOnly = uri.Query;           // "?myvalue1=hello&myvalue2=goodbye"
    string pathAndQuery = uri.PathAndQuery; // "/mypage.aspx?myvalue1=hello&myvalue2=goodbye"
    
    0 讨论(0)
  • 2020-12-10 10:58

    new Uri(System.AppDomain.CurrentDomain.BaseDirectory).Segments

    0 讨论(0)
  • 2020-12-10 11:06

    Place your string URL into a URI object and then use the AbsolutePath & Query properties to get the URL parts you need.

    Or use the PathAndQuery property to get both, which is what you need.

    More information can be found here:

    http://msdn.microsoft.com/en-us/library/system.uri_members%28v=VS.71%29.aspx

    0 讨论(0)
  • 2020-12-10 11:14

    Like this:

    new Uri(someString).PathAndQuery
    
    0 讨论(0)
提交回复
热议问题