Getting the parent name of a URI/URL from absolute name C#

后端 未结 10 734
失恋的感觉
失恋的感觉 2021-02-04 01:29

Given an absolute URI/URL, I want to get a URI/URL which doesn\'t contain the leaf portion. For example: given http://foo.com/bar/baz.html, I should get http://foo.com/bar/.

10条回答
  •  长发绾君心
    2021-02-04 02:26

    Get segmenation of url

    url="http://localhost:9572/School/Common/Admin/Default.aspx"
    
    Dim name() As String = HttpContext.Current.Request.Url.Segments
    
    now simply using for loop or by index, get parent directory name
    
    code = name(2).Remove(name(2).IndexOf("/"))
    

    This returns me, "Common"

提交回复
热议问题