473,395 Members | 1,666 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,395 software developers and data experts.

HttpWebRequest and Session Information

ALA
Hi,

does anybody know if it is possible to pass the SessionID with a web
request by using a cookie so that the invoked page in the same domain
can access the session objects of the current user?

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.CookieContainer = new CookieContainer();
HttpCookie sessionCookie =
HttpContext.Current.Request.Cookies["ASP.NET_SessionId"];
request.CookieContainer.Add(new Cookie(sessCookie.Name,
sessCookie.Value, "/", "localhost"));
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

This example doesn't seem to work for me but I do not know why... at
least I get a timeout when I execute the code above although the
mechanism works for every other cookie type, too. If I start a
HttpWebRequest without any session information, the target page has a
new and different sessionID than the soure page.

Thanks for the help

Andre

Oct 7 '07 #1
1 5631
In theory you create CookieContainer once and use it with every request.
HttpWebRequest will automaticly use it and update if needed.
You do not need to populate/repopulate it every time.

Example:
CookieContainer myContainer = new CookieContainer();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("login.aspx");
request.CookieContainer = myContainer;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
.......

request = (HttpWebRequest)WebRequest.Create("secondpage.aspx ");
request.CookieContainer = myContainer;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
PS: I belive the cookie's name fro ASP.NET session is changing all the time
(when .NET application restarts)
and it's different than ASP.NET_SessionId
So HttpContext.Current.Request.Cookies["ASP.NET_SessionId"];
should always be null.

George.


"ALA" <an**********@googlemail.comwrote in message
news:11*********************@o80g2000hse.googlegro ups.com...
Hi,

does anybody know if it is possible to pass the SessionID with a web
request by using a cookie so that the invoked page in the same domain
can access the session objects of the current user?

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.CookieContainer = new CookieContainer();
HttpCookie sessionCookie =
HttpContext.Current.Request.Cookies["ASP.NET_SessionId"];
request.CookieContainer.Add(new Cookie(sessCookie.Name,
sessCookie.Value, "/", "localhost"));
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

This example doesn't seem to work for me but I do not know why... at
least I get a timeout when I execute the code above although the
mechanism works for every other cookie type, too. If I start a
HttpWebRequest without any session information, the target page has a
new and different sessionID than the soure page.

Thanks for the help

Andre

Oct 8 '07 #2

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

Similar topics

3
by: Hardik Shah | last post by:
Hi, I am calling an ASP.Net page from an ASP classic application but need the .Net page to have access to ASP classic's session variables. I am using HTTPWebRequest to call ASP classic page...
15
by: warlord | last post by:
I have a windows client app that is trying to download a file from a web server but I always get the following error when I call the GetResponse method of the Request object. The remote server...
2
by: Keith Patrick | last post by:
I'm trying to programmatically post data to another page within my ASP.Net app. Not POSTing is not an option (I can't store this data in my session, context, hidden fields, or anything else...I've...
11
by: Keith Patrick | last post by:
Could someone explain to me the relationship between these two classes? I am ripping my hair out trying to divert an HttpRequest to a new location via an HttpWebRequest, but I cannot get my...
3
by: Amil | last post by:
Please don't repond to this if you are guessing or just don't know the answer. I'm trying to login to a backend system running Java/Tomcat. I create a HttpWebRequest with the login data and do...
1
by: davvel | last post by:
It has been 6 days of re-writing the same code in different ways to try and avoid a getResponse Timeout which haunted me for much too long now. I am trying to do a very simple thing which is...
1
by: Manso | last post by:
Hi, I have an ASP.NET 1.1 app running on Windows XP SP2 that is requesting information from a WebService which works just fine. Another part of the app is doing a server-side post to antoher...
3
by: yoni | last post by:
Hi, I am using HttpWebRequest to get the content of a web page. the call to this web page is creating a session on the server. then, I wish to get the content of a 2nd web page on the same site,...
10
by: rlueneberg | last post by:
I am trying to foward the old sessionID using "Session.SessionID" to an HttpWebRequest CookieContainer so that I can capture the requested page session variables but it is not working as it is...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.