Remove last segment of Request.Url

前端 未结 5 618
旧巷少年郎
旧巷少年郎 2021-01-07 22:59

I would like to remove the last segment of Request.Url, so for instance...

http://www.example.com/admin/users.aspx/deleteUser

5条回答
  •  时光说笑
    2021-01-07 23:40

    To remove the last segment of Request.Url it is enough to subtract from absolute uri the length of last segment.

    string uriWithoutLastSegment = Request.Url.AbsoluteUri.Remove(
      Request.Url.AbsoluteUri.Length - Request.Url.Segments.Last().Length );
    

提交回复
热议问题