Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1838498
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:29:08+00:00 2026-05-17T06:29:08+00:00

This is quite straight forward. I’m calling a web-service (.asmx, with session enabled) from

  • 0

This is quite straight forward.
I’m calling a web-service (.asmx, with session enabled) from a c# application.

I want each call to be with the same session key as the previous one (as opposed to creating a new session key each time).

Here’s my (nothing-out-of-the-ordinary) code:

public string invokeMethod(string methodUrl)
{
 HttpWebRequest req = (HttpWebRequest)WebRequest.Create(methodUrl);
 req.Method = "GET";
 req.ContentLength = 0;
 var result = new StringBuilder();
 using (HttpWebResponse res = (HttpWebResponse)req.GetResponse())
 {
   StreamReader sr = new StreamReader(res.GetResponseStream());
   result.Append(sr.ReadToEnd());
 }
 return result.ToString();
}  

Now I want to call it again, in the same session.

Added: Thanks to Waleed‘s answer, I think I should be doing (after retrieving the session id) something like:
Added once more: This is how it’s done:

if (!string.IsNullOrEmpty(currentSessionID))
{
  Cookie cookie = new Cookie("ASP.NET_SessionId", currentSessionID);
  cookie.Domain=myDomain;  //Will not work without this line!
  req.CookieContainer.Add(cookie);  
}

Thanks again.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T06:29:08+00:00Added an answer on May 17, 2026 at 6:29 am

    If I understand the question correctly, I believe you’ll need to get the session cookie from the response (the first time you call the web service) and add it to the request in the subsequent calls.

    Edit:

    Using CookieContainer is the correct way but be aware that it’s null by default so you’ll have to to assign a CookieContainer object to the property before making the request (see the example code in the MSDN’s article).

    As to the cookie name, the default name for ASP.NET session cookie is ASP.NET_SessionId, but the name can be different as it can be changed in web.config, or they might not be using ASP.NET sessions (their own implementation for example), so you’ll have to check the cookies you get from the domain of that application (You can use an HTTP sniffer like Fiddler, or more easily if you’re using FireFox or Chrome, you can check the names and contents of the cookies you get from that domain in the options dialog box).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm hoping that someone can provide a simple, straight forward example of extending the
This is quite straightforward: I have three tables: Questions: ID (PK) Body QuestionsAndAnswers: QuesionID
I'm using Ubuntu 10, python 2.6.5 I'm following this tutorial: http://www.djangobook.com/en/2.0/chapter02 I followed all
Suppose I am processing a large amount of incoming data from multiple threads. I
Just wrote a short script of copying all my tables into another local database.
I know how to use an ActionListener class to pick up an actionPerformed event
The inverse question of How can I transform XML into a List or String[]?
I am trying to build an app on my wife's phone that pranks her
I am new to R and keen to learn but am finding myself particularly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.