title: Response.Redirect in a HttpModule
body: <p>I am trying to redirect to a url from a HttpModule and nothing seems to work, I have tried the following</p>
  
  <pre><code>(sender as HttpApplication).Context.RewritePath(url);
  (sender as HttpApplication).Response.Redirect(url, true);
  </code></pre>
  
  <p>Does anyone know the correct code?</p>
  
  <p>Here's the code for the HttModule, I am intercepting requests for certain PDF document in our CMS and adding the date to the PDF, saving it to the filesystem, then trying to redirect to it</p>
  
  <pre><code>private void Application_EndRequest(object sender, System.EventArgs e)
  {
      HttpContext context = HttpContext.Current;
      HttpApplication appContext = sender as HttpApplication;
  
      ADXSTUDIO.Documents.Document document = CmsContext.Current.Document;
  
      if (document != null &amp;&amp; document.Type.Equals("adxResource.1"))
      {
          if (document.GetAttributeValue&lt;bool&gt;("AppendDateToPDF") &amp;&amp; HttpContext.Current.Request.QueryString["a"] == null)
          {
              context.Response.Clear();
  
              string issueDate = "Issue Date: " + DateTime.Now.ToString("HH:mm dd/MM/yyyy");
  
              Guid id = Guid.NewGuid();
              string filepath1 = HttpContext.Current.Server.MapPath(string.Format("~/appforms/{0}_template.pdf", id));
              string filepath2 = HttpContext.Current.Server.MapPath(string.Format("~/appforms/{0}.pdf", id));
              string url = string.Format("/appforms/{0}.pdf", id);
  
              PdfReader reader = new PdfReader(document.Url + "&amp;a=1");
              PdfStamper stamper = new PdfStamper(reader, new FileStream(filepath1, FileMode.Create));
              AddVerticalTextBox(stamper, "PageOneDownloadDate", 1);
              stamper.Close();
              reader.Close();
  
              reader = new PdfReader(filepath1);
              stamper = new PdfStamper(reader, new FileStream(filepath2, FileMode.Create));
              stamper.AcroFields.SetField("PageOneDownloadDate", issueDate);
              stamper.FormFlattening = true;
              stamper.FreeTextFlattening = true;
              stamper.Close();
              reader.Close();
  
              File.Delete(filepath1);
  
              //context.RewritePath(url);
              (sender as HttpApplication).Context.RewritePath(url);
              //(sender as HttpApplication).Response.Redirect(url, true);
          }
      }
  }
  </code></pre>