Given a URI like:
/path/page/?param1=value1¶m2=value2
How would this be generated with:
Url.Action("page","path", new { param1 = "value", param2 = "value2" })
What would be the cleanest way to strip the query string so that it works out /path/page/?
After searching in SO specifically and for a wider Google search, the best answer I found was to create a Uri object and use uri.GetLeftPart(UriPartial.Path)that I already know and use for absolute URIs.
The problem is that this will not work for relative URIs, and both do
Uri uri = new Uri(new Uri("http://www.fakesite.com"), myRelativeUri)
string cleanUri = uri.AbsolutePath
and
string cleanUri = myRelativeUri.Substring(0, myRelativeUri.IndexOf('?'))
look messy.
source
share