I would like to remove the last segment of Request.Url
, so for instance...
http://www.example.com/admin/users.aspx/deleteUser
Much the same as @Oded's answer, but using a UriBuilder instead:
var uri = new Uri("http://www.example.com/admin/users.aspx/deleteUser");
var newSegments = uri.Segments.Take(uri.Segments.Length - 1).ToArray();
newSegments[newSegments.Length-1] =
newSegments[newSegments.Length-1].TrimEnd('/');
var ub=new UriBuilder(uri);
ub.Path=string.Concat(newSegments);
//ub.Query=string.Empty; //maybe?
var newUri=ub.Uri;