G
Guest
I am trying to call a ASPX page using HttpWebRequest class and pass cookie information to it. My ASPX pages gets called just fine, however none of the request cookies are available to the ASPX page. What do I need to do to have the cookies sent along with the request
Below is the code snippet from the function I an using I am using to achieve the above. EVerything works except that I do not see any cookies in request object for the ASPX page and hence no cookies are returned back
-----------------------------------------------------------------------
CookieContainer cc = new CookieContainer()
Url = _serverName + "(" + mungedsessionID + ")/MyDirectory/MyPage.aspx?mode=" + mode + "&action=" + action + "&key=" + key + "&value=" + keyValue + "&valueType=" + valueType
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url)
request.Method = @"GET"
request.ContentType = @"text/html";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
_cookie1.Domain = _serverName; // set domain for cookie1. It has already been created in other functions
_cookie2.Domain = _serverName
cc.Add(_cookie1)
cc.Add(_cookie2)
request.CookieContainer = cc
HttpWebResponse response = (HttpWebResponse)request.GetResponse()
// Gets the stream associated with the response
Stream receiveStream = response.GetResponseStream()
Encoding encode = System.Text.Encoding.GetEncoding("utf-8")
// Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader( receiveStream, encode )
keyValue = readStream.ReadToEnd()
response.Cookies = request.CookieContainer.GetCookies(request.RequestUri)
foreach (Cookie c in response.Cookies
switch (c.Name
case COOKIE_1_NAME
_cookie1 = c
break
case COOKIE_2_NAME
_cookie2 = c
break
// Releases the resources of the response
response.Close()
// Releases the resources of the Stream
readStream.Close()
-----------------------------------------------------------------------
Below is the code snippet from the function I an using I am using to achieve the above. EVerything works except that I do not see any cookies in request object for the ASPX page and hence no cookies are returned back
-----------------------------------------------------------------------
CookieContainer cc = new CookieContainer()
Url = _serverName + "(" + mungedsessionID + ")/MyDirectory/MyPage.aspx?mode=" + mode + "&action=" + action + "&key=" + key + "&value=" + keyValue + "&valueType=" + valueType
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url)
request.Method = @"GET"
request.ContentType = @"text/html";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
_cookie1.Domain = _serverName; // set domain for cookie1. It has already been created in other functions
_cookie2.Domain = _serverName
cc.Add(_cookie1)
cc.Add(_cookie2)
request.CookieContainer = cc
HttpWebResponse response = (HttpWebResponse)request.GetResponse()
// Gets the stream associated with the response
Stream receiveStream = response.GetResponseStream()
Encoding encode = System.Text.Encoding.GetEncoding("utf-8")
// Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader( receiveStream, encode )
keyValue = readStream.ReadToEnd()
response.Cookies = request.CookieContainer.GetCookies(request.RequestUri)
foreach (Cookie c in response.Cookies
switch (c.Name
case COOKIE_1_NAME
_cookie1 = c
break
case COOKIE_2_NAME
_cookie2 = c
break
// Releases the resources of the response
response.Close()
// Releases the resources of the Stream
readStream.Close()
-----------------------------------------------------------------------