0

I am trying to do :

foreach (JProperty o in obj.Properties())
{
   string ke = o.Name.ToString();
   string va = o.Value.ToString();
   HttpContext.Current.Request.QueryString.Add(ke,va);
}

but it gives me the error "collection is read-only"

HOW can I add values to querystring then ?

Thanks

1
  • 1
    It shows "read-only", means you can't add. You have to create a new one and assign the query from the beginning. Commented Mar 3, 2016 at 10:12

1 Answer 1

1

Request.QueryString is the url you recieve from the server. You cant change it. What you can do is execute a response redirect with the query string like so:

string qs = "?";
foreach (JProperty o in obj.Properties())
{
   qs += o.Name.ToString();
   qs += "=" + o.Value.ToString() + "&";
}
Response.Redirect("url/index" + qs);
Sign up to request clarification or add additional context in comments.

4 Comments

so in fact with redirect it will recall the handler?
Not recall but call. It will create/add a querystring and call a new handler.
in my solution I can not call again. so in this case there is no way to add values to QueryString , am I right?
Yes, cant change it unless you call again. If you REALLY REALLY insist on changing the querystring, something that is BAD PRACTICE then check out stackoverflow.com/questions/15450505/… which gives you an option to change it BEFORE you recieve it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.