如何清除Request.Querystring [英] How to clear Request.Querystring

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

问题描述

您好,



如何清除Request.Querystring。

我已经在谷歌和一些博客网站上搜索了,他们建议我。但他们不工作。

当我试图Request.QueryString.Clear();这个时候发生了一个错误,错误是收集是只读的。

请建议我这个。







谢谢和问候,

解决方案

坚持这个链接,你会得到答案。



删除(删除)查询字符串在ASP.NET [ ^ ]





谢谢

AARIF


1。在第一步中,我们需要获取当前URL文本



string url = HttpContext.Current.Request.Url.AbsoluteUri;





2.然后从URL中拆分查询字符串部分。





string [] separateURL = url.Split('?');





这里我试图将字符串拆分成字符串数组也可以通过其他方式完成。但这里的主要目的是提取URL的查询字符串部分。





3在ASP.NET中,System.web命名空间中有HttpUtility类,它有助于将查询字符串参数解析为名称 - 值集合对象。





NameValueCollection queryString = System.Web.HttpUtility.ParseQueryString(separateURL [1]); //通过Querystring部分。



现在我们可以修改值,例如





queryString [member] = txtMemberSearch.Text;

queryString [phone] = txtPhoneNumber.Text;



我们也可以删除一些查询字符串部分。





queryString.Remove(date);

queryString.Remove(mode);





我们可以添加另一个查询字符串值,如果它之前不存在,如下所示。





queryString [priority] = ddlPriority.SelectedItem.Text; //从下拉列表中选择的项目。





4.重置我们需要的所有参数后,我们需要转换该名称 - 值将对象收集到字符串中并追加到查询中。





url = separateURL [0] +? + queryString.ToString();





现在,您可以使用此新URL来导航所有需要的参数。


Hello,

How to clear Request.Querystring.
I have already search on google and some blogging site's, they have suggested me. but they don't work.
when i have trying to "Request.QueryString.Clear();" this that time one error is occurred and the error is "Collection is read-only."
Please suggest me for that.



Thanks & Regards,

解决方案

Go on this Link defiantly you will Get your Answer .

Removing (Deleting) Querystring in ASP.NET[^]


Thanks
AARIF


1. In first step, we need to get the Current URL text

string url = HttpContext.Current.Request.Url.AbsoluteUri;


2. Then splitting the query string part from URL.


string[] separateURL = url.Split('?');


Here I have tried to split the string into a string array,which can be done by other ways also.But here main aim is to extract the query string part of the URL.


3. In ASP.NET there is HttpUtility class inside System.web namespace, which helps to parse the query string parameters into a name-value collection object.


NameValueCollection queryString = System.Web.HttpUtility.ParseQueryString(separateURL[1]) ; // Pass the Querystring part.

Now we can modify the value such as


queryString["member"] = txtMemberSearch.Text;
queryString["phone"] = txtPhoneNumber.Text;

Also we can Remove some query string part .


queryString.Remove("date");
queryString.Remove("mode");


We can add another query string value if it does not exists before as given below.


queryString["priority"] = ddlPriority.SelectedItem.Text; //selected item from dropdown list.


4. After resetting all parameters of our need, we need to convert that name-value collection object into string and append to the query.


url = separateURL[0] + "?" + queryString.ToString();


Now, you can use this new URL to navigate with all desired parameters.


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

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