3

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");
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
user2232273
  • 4,898
  • 15
  • 49
  • 75
  • 6
    Use a Redirect. It looks like you're trying to modify the URL with server side code, but it doesn't work like that because the client and server are separate. You may wish to read about client/server architectures and HTTP. – Ian Newson Nov 04 '13 at 15:26
  • ah ok.. i understand now what you mean... – user2232273 Nov 04 '13 at 15:30

1 Answers1

7

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);
Community
  • 1
  • 1
Jace Rhea
  • 4,982
  • 4
  • 36
  • 55