加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – MVC – 删除QueryString

发布时间:2020-12-16 01:58:13 所属栏目:百科 来源:网络整理
导读:我正在做一个项目,我想做的是清除我的网址栏中的查询字符串. 但直到现在我还没多运气.. 希望有人可以帮我这个.. 这是我尝试做的代码之一: System.Reflection.PropertyInfo isreadonly = typeof(System.Collections.Specialized.NameValueCollection).GetPro
我正在做一个项目,我想做的是清除我的网址栏中的查询字符串.

但直到现在我还没多运气..

希望有人可以帮我这个..

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

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是用户请求的,它已经发生在过去.

您可能希望将用户重定向到不带查询字符串的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);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读