Querystring值未在URL中清除 [英] Querystring value is not getting cleared in URL

查看:83
本文介绍了Querystring值未在URL中清除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试清除我的网址中的Querystring值,但下面的工作不正确是我的代码..请找出解决方案



Hi,
I am trying to clear my Querystring value in my URL but it''s not working below is my code..Please find out the solution

SqlConnection cnn = new SqlConnection(Conn);
                SqlCommand cmd = new SqlCommand("Update tbl_Country set Name='"+txtName.Text.Trim()+"',CountryImg='"+Img+"' where Id="+id+"", cnn);
                cnn.Open();
                cmd.ExecuteNonQuery();
                FillGrid();
                txtName.Text = "";
                ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script language='javascript'>alert('Country Updated successfully')</script>");
                //Request.QueryString.Remove("id");
                //Request.QueryString.Clear();
                PropertyInfo isReadOnly = typeof(System.Collections.Specialized.NameValueCollection).GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);
                isReadOnly.SetValue(this.Request.QueryString, false, null);
                this.Request.QueryString.Remove("id");
                cnn.Close();

推荐答案

您不能直接删除查询字符串。它是HttpRequest对象的readonly属性。您可以从Request对象中读取所有查询字符串并根据需要创建新的查询字符串,并使用新的查询字符串Response.Redirect该页面。

链接将对您有所帮助。
You can not directly remove query string. It is readonly property for HttpRequest object. What you can just read all querystring from Request object and create new querystring as you needed and Response.Redirect that page with new querystring.
The Link will be helpful for you.


var nameValueCollection = HttpUtility.ParseQueryString(HttpContext.Current.Request.QueryString.ToString());
nameValueCollection.Remove(tenantPropertyName);
string url = HttpContext.Current.Request.Path + "?" + nameValueCollection;


这篇关于Querystring值未在URL中清除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆