2013-11-04 78 views
3

我正在处理一个项目,我想要做的是清除我的网址栏中的查询字符串。MVC - 删除查询字符串

,但到现在为止我haven't多少运气..

希望有人能帮助我这个..

这就是我想要做的我的代码之一:

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"); 
+6

使用重定向。它看起来像你试图用服务器端代码修改URL,但它不能这样工作,因为客户端和服务器是分开的。您不妨阅读客户端/服务器体系结构和HTTP。 –

+0

好的..我现在明白你的意思了... – user2232273

回答

7

请求的网址无法更改。请求的URL是用户请求的内容,它已经发生在过去。

您可能希望将用户重定向到没有查询字符串的url。取自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);