473,799 Members | 3,178 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Cre ate(url);
request.CookieC ontainer = new CookieContainer ();
HttpCookie sessionCookie =
HttpContext.Cur rent.Request.Co okies["ASP.NET_Sessio nId"];
request.CookieC ontainer.Add(ne w Cookie(sessCook ie.Name,
sessCookie.Valu e, "/", "localhost" ));
HttpWebResponse response = (HttpWebRespons e)request.GetRe sponse();

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 5688
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.Cre ate("login.aspx ");
request.CookieC ontainer = myContainer;
HttpWebResponse response = (HttpWebRespons e)request.GetRe sponse();
.......

request = (HttpWebRequest )WebRequest.Cre ate("secondpage .aspx");
request.CookieC ontainer = myContainer;
HttpWebResponse response = (HttpWebRespons e)request.GetRe sponse();
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_Session Id
So HttpContext.Cur rent.Request.Co okies["ASP.NET_Sessio nId"];
should always be null.

George.


"ALA" <an**********@g ooglemail.comwr ote in message
news:11******** *************@o 80g2000hse.goog legroups.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.Cre ate(url);
request.CookieC ontainer = new CookieContainer ();
HttpCookie sessionCookie =
HttpContext.Cur rent.Request.Co okies["ASP.NET_Sessio nId"];
request.CookieC ontainer.Add(ne w Cookie(sessCook ie.Name,
sessCookie.Valu e, "/", "localhost" ));
HttpWebResponse response = (HttpWebRespons e)request.GetRe sponse();

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
2912
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 which could then return the session values. But the values are always blank. If I do a Response.Redirect() to call the ASP page, it returns the values okay. But I cannot do a Response.Redirect() as I just need to access some session variables and...
15
515
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 returned an error: (404) Not Found. When I run it against a website on my local machine everything works perfectly, but not against the remote server. I'm sure it's a security or permissions problem of some sort, but I'm not sure where to start.
2
4827
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 exhausted all my other options, so I have to get this scenario working). Basically, if I POST the data normally, it works fine, except the target page has a new session ID, so I lost the session data that I *do* transfer around. However, if I...
11
15896
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 session xfer to work, possibly due to the cookies not being compatible. I've spent over a week trying to get the HWR to integrate nicely with my app, but I cannot get the session to transfer, and it'd probably take me even longer if I tried to digest...
3
3958
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 a POST. This works fine. The HttpWebResponse content I get back is just javascript "window.location=xxx" (with normal html around it). The HttpWebResponse also contains a java session id cookie. Fine so far. I want to go to the new location...
1
2793
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 prooving the most difficult in my career. Scrape a screen which has several session variables within it, and send this page to an e-mail. I have two pages in my application webform1.aspx and webform2.aspx, in webform1.aspx I set several session...
1
5846
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 system using HttpWebRequest. Code as follows: ============================== Dim objWebReq As HttpWebRequest Dim objStream As Stream
3
3128
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, but this 2nd web page reads the session created on the 1st page. so when i call it with HttpWebRequest, it lost the session. anybody has a tip or a code snippet that shows me how do i make the server retain the session between two HttpWebRequest...
10
29988
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 supposed to. The HttpResponse object always returns a different sessionID from the old one which I am trying to force. Why is objRequest not carrying over the old SessionID? private String ReadHtmlPage(string url) { String result = string.Empty;
0
9686
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9540
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10475
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10222
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10026
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9068
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7564
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.