title: Update HttpContext.Current.Request.QueryString
body: <p>I have a function that is attempting to filter data based on what is in the <code>HttpContext.Current.Request.QueryString</code>. A recent "improvement" has changed how I have to filter what's being shown. Now I need to update the <code>QueryString</code> before my filtering functions run. Based on some other StackOverflow questions I have tried a few different ways but they haven't work.</p>
  
  <pre><code>    var queryString = HttpContext.Current.Request.QueryString;
      var nameValues = HttpUtility.ParseQueryString( queryString.ToString() );
      nameValues.Add( "IsDeleted", "False" );
      string url = HttpContext.Current.Request.Url.AbsolutePath;
      string updatedQuerySring = "?" + nameValues.ToString();
      HttpContext.Current.Response.Redirect( url + updatedQuerySring );
  </code></pre>
  
  <p>The above threw a system.Web.HttpException error "Server cannot set status after HTTP headers have been sent."</p>
  
  <pre><code>HttpContext.Current.Request.QueryString.Add( "IsDeleted", "False" );
  </code></pre>
  
  <p>and</p>
  
  <pre><code>    NameValueCollection newQuery = new NameValueCollection();
      foreach( var key in queryString.Keys ){
          var value = queryString[ key.ToString()];
          newQuery.Add( key.ToString(), value );
      }
      newQuery.Add( "IsDeleted", "False" );
      HttpContext.Current.Request.QueryString = newQuery;
  </code></pre>
  
  <p>both come up with "Error    20  Property or indexer 'System.Web.HttpRequest.QueryString' cannot be assigned to -- it is read only". How do you update the <code>QueryString</code> so that I can add the <code>IsDeleted</code> filter it? </p>
  
  <p><em>EDIT</em> it was suggested to keep it in a session or tempdata variable but that won't work as it is needed in more than 1 redirect.</p>