title: WebRequest - Prevent redirection
body: <p>I am using a <code>WebRequest</code> to read an HTML site. The server seems to be redirecting my request.</p>
  
  <p>My Code is similar to the following:</p>
  
  <pre><code>    String URI = "http://www.foo.com/bar/index.html"
      WebRequest req = WebRequest.Create(URI);
      WebResponse resp = req.GetResponse();
      StreamReader sr = new StreamReader(resp.GetResponseStream());
      String returnedContent = sr.ReadToEnd();
  </code></pre>
  
  <p>When I check the content of the <code>returnedContent</code> it contains the content from a redirection like "http://www.foo.com/FOO_BAR/index.html". I am sure my requested URL exists since it is part of the recieved response (as an IFrame).</p>
  
  <p>Is there a way to prevent the <code>WebResponse</code> to be redirected and get the content of the requested url?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Setting <code>req.AllowAutoRedirect = false</code> leads to a <code>302 Found</code> state code, but does not deliver the acutal content.</p>
  
  <p>Some more details:
  My requested url was <code>http://www.foo.com/bar/index.html</code> the content I receive is located in <code>http://www.foo.com/FOO_BAR/index.html</code></p>
  
  <p>The response looks similar to this:</p>
  
  <pre><code>&lt;body&gt;
      &lt;div&gt;
          &lt;iframe src="/foo/index.html"&gt;&lt;/iframe&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>