If you want to hide the query string in the URL, you need to use POST to deliver the ID in the body of the request instead of the query string.
Yes. The entire text of an HTTPS session is secured by SSL. That includes the query and the headers.
The value of Request. QueryString(parameter) is an array of all of the values of parameter that occur in QUERY_STRING. You can determine the number of values of a parameter by calling Request. QueryString(parameter).
Here's a simpler solution:
var uri = new Uri("http://www.example.com/mypage.aspx?myvalue1=hello&myvalue2=goodbye");
string path = uri.GetLeftPart(UriPartial.Path);
Borrowed from here: Truncating Query String & Returning Clean URL C# ASP.net
You can use System.Uri
Uri url = new Uri("http://www.example.com/mypage.aspx?myvalue1=hello&myvalue2=goodbye");
string path = String.Format("{0}{1}{2}{3}", url.Scheme,
Uri.SchemeDelimiter, url.Authority, url.AbsolutePath);
Or you can use substring
string url = "http://www.example.com/mypage.aspx?myvalue1=hello&myvalue2=goodbye";
string path = url.Substring(0, url.IndexOf("?"));
EDIT: Modifying the first solution to reflect brillyfresh's suggestion in the comments.
This is my solution:
Request.Url.AbsoluteUri.Replace(Request.Url.Query, String.Empty);
Good answer also found here source of answer
Request.Url.GetLeftPart(UriPartial.Path)
Request.RawUrl.Split(new[] {'?'})[0];
My way:
new UriBuilder(url) { Query = string.Empty }.ToString()
or
new UriBuilder(url) { Query = string.Empty }.Uri
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With