Session Maintainence

How to maintain Session in HttpWebRequest and HttpWebResponse without using Webservices and ASP objects


Answer this question

Session Maintainence

  • sptma

    You will likely need to make your httpwebrequest accept and store cookies,
    to mimic what your browser would typically do.

    Or you can POST or the Query string to resend values.


  • _Ed Noepel

    Hi Sande,

    Already I have done this, but for session maintainence what should I do


    Kailash

  • xhh


    CookieContainer myContainer = new CookieContainer();

    // following line will add a cookie in container, which would be for all urls on the domain myDomainstr
    myContainer.Add(new Cookie("name","value","/",myDomainstr));

    HttpWebRequest request1 = (HttpWebRequest) WebRequest.Create(httpUrlString);

    // use this same container for all requests in your app
    request1.CookieContainer = myContainer;

    //you can check cookies on response.Cookies
    HttpWebResponse response = (HttpWebResponse) request.GetResponse();



    More information can be found on a great blogpost that can be found here: Establishing cookie based session with WebServices and HttpWebRequest.


  • Session Maintainence