I am trying to authenticate a HttpWebRequest. My code is like this
string url = "http://mydomain.com";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
HttpCookie cookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
req.Headers[HttpRequestHeader.Cookie] = string.Format("{0}={1}", cookie.Name, cookie.Value);
WebResponse res = req.GetResponse();
Everything goes fine till last line executes(WebResponse res = req.GetResponse();).When last line executes code execution goes back to first line(string url = “string url = “http://mydomain.com”;”;) and start again,this happens so many times that a time out exception happens.
First – not clear why url is defined like this:
This is not a valid URL. But if you have
Than you are producing a request to that same page you are in. So basically, you simply produce a loop. You call your page from a browser, it calls itself using webrequest, and it calls itself again. So in VS debugger will show you like it goes back to the first line.
Try simply change url definition like below:
If you will do that,it should work fine. Basically, as I understand, you are simply using wrong URL which creates something like a loop (or even better to say: long chain of calls)