I have a form that sometimes gets linked to with some query string parameters. The problem is that when I post back the form, the query string parameter is still there. It's not really an issue the way I have it setup, but I just don't like it being there, and could see it being a problem if you needed to check for input in a certain order.
Is there a way to clear that query string parameter in an easy, clean way? I know I could change the PostBackURL on the button, but that doesn't seem too efficient.
The only way to 'clear' the query string is to do a redirect to the same URL but without the query string part. Is there particular reason why you want it cleared? If security is the issue, try using a POST call instead or encrypt the query string.
POST should not have query param. You can implement the service to honor the query param, but this is against REST spec. "Why do you pass it in a query param?" Because, like for GET requests, the query parameters are used to refer to an existing resource.
A POST request can include a query string, however normally it doesn't - a standard HTML form with a POST action will not normally include a query string for example.
delete() The delete() method of the URLSearchParams interface deletes the given search parameter and all its associated values, from the list of all search parameters.
put this at the bottom of your page?
<script language="javascript" type="text/javascript">
document.forms[0].action = window.location.pathname;
</script>
I was stuck with same issue.
I solved it using the following code block:
private void ClearQueryString()
{
PropertyInfo isreadonly = typeof(System.Collections.Specialized.NameValueCollection).GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);
isreadonly.SetValue(this.Request.QueryString, false, null);
this.Request.QueryString.Remove("Action");
this.Request.QueryString.Remove("param1");
this.Request.QueryString.Remove("paramN");
}
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