我正在做一个项目,我想做的是清除我的网址栏中的查询字符串。
但到现在为止我运气不太好..
希望有人能帮我解决这个问题..
这是我尝试做的代码之一:
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");
最佳答案
请求的 url 不能更改。 Request的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);
关于c# - MVC - 删除查询字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19771027/