smithvoice.com
 Y'herd thisun? 

“! could either watch it happen, or be part of it.”
-Elon Musk



Simple redirect test - simple oversight

TaggedCoding, ASP.Net

The logs show that your pages are redirecting correctly... but a spider type test app shows everything as being status 200 OK... dagnabbit, don't forget to switch off that one little property: AllowAutoRedirect.

Without that property being set to false, your redirects will just work and the calls from your test code will return the final response for the target call.

 

string ret = string.Empty;
 try
 {
 HttpWebRequest req =
 (HttpWebRequest)WebRequest.Create(txtUrl.Text);
 req.Method = "POST";
 req.ContentType = "text/xml";
 req.ContentLength = 0;
 req.Timeout = 10000;
 req.AllowAutoRedirect = false;
 HttpWebResponse resp =
 (HttpWebResponse)req.GetResponse();
 HttpStatusCode statusCode = resp.StatusCode;
 WebHeaderCollection col = resp.Headers;
 ret = "Test success:" + ((int)statusCode).ToString() + " - " + statusCode.ToString();
 resp.Close();
 }
 catch (WebException ex)
 {
 ret = "WebException Message: " + ex.Message;
 if (ex.Status == WebExceptionStatus.ProtocolError)
 {
 ret += "\nProtocol Error Status Code: " +
 ((HttpWebResponse)ex.Response).StatusCode +
                        ((HttpWebResponse)ex.Response).StatusDescription;
 }
 }
 catch (Exception ex)
 {
 ret = "General Exception: " + ex.Message;
 
  
 MessageBox.Show(ret);
home     who is smith    contact smith     rss feed π
Since 1997 a place for my stuff, and it if helps you too then all the better smithvoice.com