c# - MVC - 删除查询字符串

标签 c# asp.net asp.net-mvc

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

但到现在为止我运气不太好..

希望有人能帮我解决这个问题..

这是我尝试做的代码之一:

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/

相关文章:

c# - 大拇指在线角点上不会重新定位点

c# - 从代码设置自定义 MarkupExtension

'all methods' 的 C# 委托(delegate)或 Func?

c# - 通过 Entity Framework 创建记录时未插入数据库默认值

c# - 在这种情况下如何正确使用 .ToLower() ?

c# - WCF web.config 中的 readerQuotas 与请求限制

c# - 如何加载mp3歌曲并在aspx网页中显示?

css - 使图片充当来自 actionlink 的链接

css - 具有 Bootstrap 主题的 mvc 中的下拉列表

c# - 同一个应用程序可以同时是 NServiceBus 的发布者/订阅者吗?