Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC - Delete QueryString

I'm working on a project and I want to do is to clear the querystring in my url bar.

but until now i haven´t much luck..

hope that someone can help me with this..

this is one of my code which i trying to do:

System.Reflection.PropertyInfo isreadonly = typeof(System.Collections.Specialized.NameValueCollection).GetProperty( "IsReadOnly", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
isreadonly.SetValue(this.Request.QueryString, false, null);
this.Request.QueryString.Remove("abc");
like image 829
user2232273 Avatar asked Apr 09 '26 07:04

user2232273


1 Answers

The url of the Request can not be changed. The url of the Request is what the user has requested, it has already happened in the past.

You probably want to redirect the user to the url without the query string. Taken from this question...

var uri = new Uri("http://www.example.com/mypage.aspx?myvalue1=hello&myvalue2=goodbye");
string path = uri.GetLeftPart(UriPartial.Path);
return Redirect(path);
like image 78
Jace Rhea Avatar answered Apr 11 '26 20:04

Jace Rhea