473,805 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get session cookies from webrequest and pass then to new request

I am making a console app that requests pages from our site one after
another. Each request starts a new session, What I want to do is make all
requests in the same session.

How can I do this.

I was hoping to be able to get the session back from first request and then
set them on each further request.

Any ideas?

Jul 3 '08 #1
3 8839
ThatsIT.net.au used his keyboard to write :
I am making a console app that requests pages from our site one after
another. Each request starts a new session, What I want to do is make all
requests in the same session.

How can I do this.

I was hoping to be able to get the session back from first request and then
set them on each further request.

Any ideas?
There is a CookieContainer specifically for this scenario:
create one and add it to every request you issue.

Hans Kesting
Jul 3 '08 #2
ThatsIT.net.au wrote:
I am making a console app that requests pages from our site one after
another. Each request starts a new session, What I want to do is make
all requests in the same session.

How can I do this.

I was hoping to be able to get the session back from first request and
then set them on each further request.
Example of using CookieContainer :

using System;
using System.IO;
using System.Net;

namespace E
{
public class MainClass
{
public static string GetContent(stri ng url, CookieContainer
session)
{
HttpWebRequest wr = (HttpWebRequest )WebRequest.Cre ate(url);
wr.CookieContai ner = session;
string html = (new
StreamReader(wr .GetResponse(). GetResponseStre am())).ReadToEn d();
return html;
}
public static void Main(string[] args)
{
CookieContainer session = new CookieContainer ();
string login =
GetContent("htt p://localhost:8080/logintest/login.jsp?usern ame=arne&passwo rd=hemmeligt",
session);
Console.WriteLi ne(login);
string other =
GetContent("htt p://localhost:8080/logintest/other.jsp", session);
Console.WriteLi ne(other);
}
}
}

Arne
Jul 3 '08 #3
Sorry I did not get back earlier,

thanks very much ill try it

"Arne Vajhøj" <ar**@vajhoej.d kwrote in message
news:48******** *************** @news.sunsite.d k...
ThatsIT.net.au wrote:
>I am making a console app that requests pages from our site one after
another. Each request starts a new session, What I want to do is make all
requests in the same session.

How can I do this.

I was hoping to be able to get the session back from first request and
then set them on each further request.

Example of using CookieContainer :

using System;
using System.IO;
using System.Net;

namespace E
{
public class MainClass
{
public static string GetContent(stri ng url, CookieContainer
session)
{
HttpWebRequest wr = (HttpWebRequest )WebRequest.Cre ate(url);
wr.CookieContai ner = session;
string html = (new
StreamReader(wr .GetResponse(). GetResponseStre am())).ReadToEn d();
return html;
}
public static void Main(string[] args)
{
CookieContainer session = new CookieContainer ();
string login =
GetContent("htt p://localhost:8080/logintest/login.jsp?usern ame=arne&passwo rd=hemmeligt",
session);
Console.WriteLi ne(login);
string other =
GetContent("htt p://localhost:8080/logintest/other.jsp", session);
Console.WriteLi ne(other);
}
}
}

Arne
Jul 13 '08 #4

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

Similar topics

27
7135
by: mrbog | last post by:
Tell me if my assertion is wrong here: The only way to prevent session hijacking is to NEVER store authentication information (such as name/password) in the session. Well, to never authenticate a user from information you got from the session. Each secure app on a site must challenge the user for name and password, each and every time the user accesses it (not just once and then store it in the session). If a secure app is multi-page,...
1
14294
by: Craig | last post by:
I wrote a generic page to do HttpWebRequest operations based on 3 querystring parameters for the uri, username, and password for basic authentication pages. The page is designed to help with network management... You would use the page like this: http://localhost/webform1.aspx?uri=http://pagetomonitor.com&user=someuser&pass=somepass Anyway, what seems to happen is that the first 2 or 3 calls to the page with a given set of parameters...
3
6352
by: Paul | last post by:
Hello, First I want to refer to the problem "WebRequest : execute a button" of a few days ago. The way I solved it, I loose my session, and as a consequence my session variables. I don't want to keep those variables, as an alternative, as ViewState variables because I don't want to transfer to many hidden fields. This is the code I use :
3
7380
by: Karsten Grombach | last post by:
Hi, I'm trying the following: - Imitate a Logon using a Post with HttpWebRequest on remote Webserver (asp 3.0 page using https) - On success redirect to the page (encapsuled in an iframe) supplied by the remote Webserver I can successfuly logon but when I redirect to the supplied url, the webserver does not know me anymore an redirects me back to login page.. I
3
3959
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...
9
5320
by: McGeeky | last post by:
Is there a way to get a user control to remember its state across pages? I have a standard page layout I use with a header and footer as user controls. Each page uses the same layout by means of copy paste (I hear this will improve in ASP.Net 2 via master pages). When I navigate from one page to the next the header and footer user controls lose their state because they are effectively different instances of the user control. Is there...
4
11440
by: mike.biang | last post by:
I have an ASP page that is using an XMLHTTP object to request various pages from my server. I keep a single session throughout the XMLHTTP requests by bassing the ASPSESSIONID cookie through the XMLHTTP object. However, when the page requested through the XML object makes a <%Response.Redirect()%> call, a new session is created each time. Is this a flaw in the XMLHTTP Object? How can I force the session to remain the same after a...
1
5690
by: ALA | last post by:
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;
3
3171
by: ThatsIT.net.au | last post by:
I am making a console app that requests pages from our site one after another. Each request starts a new session, What I want to do is make all requests in the same session. How can I do this. I was hoping to be able to get the session back from first request and then set them on each further request. Any ideas?
0
9716
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
9596
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
10360
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10366
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
10105
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...
1
7646
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
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3845
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.