473,378 Members | 1,413 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

ASPX page does not receive any cookies in Request object when called using HttpWebRequest object.

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.Request Uri)

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()

-----------------------------------------------------------------------
Nov 16 '05 #1
1 1818
Bhupesh Saini wrote:
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.


Are you sure they're not being sent? What if you use a debugging proxy like
Fiddler to monitor the requests?

Cheers,

--
Joerg Jooss
jo*********@gmx.net

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Daniel Rimmelzwaan | last post by:
I want to send a biztalk document to an aspx page, and I need to see some sample code, because I just can't make it work. I have a port with transport type HTTP, pointing to my aspx page, something...
6
by: omyek | last post by:
I'm trying to mimic the browsing of a webpage using an HttpWebRequest. I've had a lot of luck with it so far, including logging into pages, posting form data, and even collecting and using cookies....
0
by: Mach Runner | last post by:
I am implementing a secure website using the ASP.NET FormsAuthentication model. I have taken the simplest code examples from MSDN (login.aspx,default.aspx, web.config) but cannot get proper...
4
by: Andy Fish | last post by:
Hi, I have a web app that I want to make calls back into itself (preserving the session cookies etc). I am using a System.Net.HttpWebRequest object to make the request, but I am having...
16
by: Cheung, Jeffrey Jing-Yen | last post by:
I have a windows form application that generates a request, downloads an image, and waits the user to enter in login info. Unfortunately, this image is dynamic and based on session data. I have...
2
by: Issos | last post by:
Is there a way to just receive the cookie(s) from an webrequest in ASP.NET? The function I'm using at the moment can handle cookies... but it will also get the full response of the request... I...
6
by: divya | last post by:
I have a page name edit.asp which should expire immediately .The user cannot open this page directly he has to provide a password for entering this page.thus when the user enters edit.asp , it has...
4
by: Kuldeep | last post by:
Hi All, I am trying to read the contents of a page through its URL. My code snippet is as follows: public void mtdGetPageDataHWR() { HttpWebRequest objRequ =...
0
by: vishnu | last post by:
Hi, Am trying to post the data over https and am getting error in httpwebresponse.getResponseStream.Please help me to get rid of this issue. Here is the message from immediate window ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.