Ran into a weird cookie issue
HttpWebRequest cookies are disabled for security by default.
You need to enable it. Now if you want to add cookies from your current request, since they are seperate types, you have add it manually.
my httpCookies – HttpContext.Current.Request.Cookies;
var request = (HttpWebRequest)WebRequest.Create(url);
request.CookieContainer = new CookieContainer(); //now your cookie is enabled.
//Following foreach will error out with
//unable to cast object of type ‘System.string’ to type ‘System.Web.HttpCookie’
if (HttpContext.Current.Request.Cookies.Count > 0)
foreach (HttpCookie requestCookie in HttpContext.Current.Request.Cookies) //this will error out
//something I want to do
You need to use for loop, and it will not error out. Not sure why this happens, but this is a workaround
for(var i=0; i