2

I am making web request using windows.web.http I am making calls as shown in below

namespace service
{
 public class getserinfo
    {
        public async Task<bool> call()
        {
            var client = new HttpClient();
            var uri = new Uri(www.example.com / db / login);
            var response = await client.PostAsync(uri);
            var session = await response.Content.ReadAsStringAsync(); //here it returns session which I need in classes in another for accessing different paths
        }
    }
}

How do i store session ID as public that can be accessed in any class.

Ravikumar Sharma
  • 3,678
  • 5
  • 36
  • 59
louis
  • 595
  • 3
  • 9
  • 24
  • 2
    This may help you .Please refer this [session](http://stackoverflow.com/questions/621549/how-to-access-session-variables-from-any-class-in-asp-net) – Invader Mar 24 '16 at 05:40

2 Answers2

0

You make a static class in the root of your project which can store this data to be accessed from anywhere.

user2713516
  • 2,983
  • 5
  • 23
  • 49
0

Sessions are mostly stored in the cookies (Not always). What you can do is to create a global CookieContainer variable. Make a first call to the website and store the cookie in the CookieContainer and then with each request re-use the same CookieContainer. Following code is just to give you headstart and it is not the complete code but hopefully you will get the idea. You will need to use HttpWebRequest. Don't worry HttpWebResponse has also method for Async.

    public void WebsiteCall(string url)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.CookieContainer = container;

        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        container = request.CookieContainer;
    }

Now each time you will make a call to your website then CookieContainer will be re-used and if the Session is stored in cookies by the website then you will be able to successfully keep the same session throughout your every call.

Adnan Yaseen
  • 833
  • 1
  • 15
  • 44