如何清除asp.net中的查询字符串值


你好,

如何清除查询字符串值。

例子:

response.write("sample.aspx?id=3")

我正在另一个页面获取此值,例如

int id=request.querystring["id"];

我想在更新方法中清除这个值。

我正在使用以下内容

Response.ClearContent();
Request.QueryString.Remove("id");  

但还不清楚

感谢®
文卡特

解决方案1

要清除所有查询字符串,您可以调用Request.QueryString.Clear();
这将删除 url 处的所有查询字符串
要删除特定的查询字符串,请调用 Request.QueryString.Remove(“name of the querystring”),

例子:

http://www.mypage.aspx?id=123
Request.QueryString.Remove("id");

或者你可以使用

Request.QueryString.Clear();

这将删除或查询字符串

例子

http://www.mypage.aspx?id=123&date=29/8/2008
Request.QueryString.Clear();

结果
不带两个查询字符串(id、日期)的 URL;

解决方案3

PropertyInfo isreadonly = typeof(System.Collections.Specialized.NameValueCollection).GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);
                // make collection editable
                isreadonly.SetValue(this.Request.QueryString, false, null);
                // remove
                this.Request.QueryString.Remove("id");

您好,使用上面的代码解决了这个问题

解决方案2

您可以使用

Request.QueryString.Clear();

清除所有查询字符串

解决方案7

解决方案 2 不起作用,因为 Request.QueryString 是只读的。

コメント

タイトルとURLをコピーしました