how to modify HttpRequest QueryString value in class library,i current can get QueryString value and modify,but how to write the modified QueryString to HttpRequest:
public static HttpRequest ModiQueryString(HttpRequest request)
{
var nv = new NameValueCollection(request.QueryString);
foreach (string key in nv.Keys)
{
nv[key] = "abc";
}
//here how to let request.QueryString equal nv
return request;
}
because the request.QueryString is read-only,so how can i do?
who can help me?thanks
if i create a new HttpRequest,is i can use:
StringBuilder newQuery=new StringBuilder();
foreach(string key in nv.Keys)
{
newQuery.AppendFormat("{0}={1}",key,FilterKeyWord(nv[key]));
}
HttpRequest newRequest = new HttpRequest("", request.Url, newQuery.ToString());
return newRequest;
This is simply impossible because
QueryStringis not settable and the class issealedto boot.You should either modify the query string before the request is constructed, or if you only have an
HttpRequestto work with then keep a temporary copy of the query string (which you can edit) and construct anotherHttpRequestwith the modified query string.