How to get ASP.NET_SessionId via ActiveBrowser?

6 posts, 0 answers
  1. Jet
    Jet avatar
    10 posts
    Member since:
    Oct 2012

    Posted 25 Oct 2012 Link to this post

    I'm using Telerik Testing Framework in my testing project, I want to get the ASP.NET_SessionId, I can get it from the headers of web response, can I get it via ActiveBrowser?
  2. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 30 Oct 2012 Link to this post

    Hi Jet,

    I apologize for the delay in getting back to you on this. Currently you have two options to get the ASP.NET_SessionId. 

    1. The first that you already know is via the headers of web response. Here's a sample code:
        ResponseListenerInfo li = new ResponseListenerInfo(ResponseHandler);
        Manager.Http.AddBeforeResponseListener(li);      
     
        Manager.ActiveBrowser.NavigateTo("https://login.asp.net/login/signin.aspx?ReturnUrl=http://www.asp.net/get-started");
        Manager.ActiveBrowser.WaitUntilReady();
     
        Manager.Http.RemoveBeforeResponseListener(li);
     
     
    private void ResponseHandler(object sender, HttpResponseEventArgs e)
    {           
        System.Collections.Specialized.NameValueCollection headers = e.Response.Headers;
        Log.WriteLine(headers["Set-Cookie"]);
    }

    See this article for more information on how to use the Http Proxy.

    2. The second method which I recommend is via the ActiveBrowser. The following code demonstrates how to do that:
    Manager.ActiveBrowser.NavigateTo("https://login.asp.net/login/signin.aspx?ReturnUrl=http://www.asp.net/get-started");
    Manager.ActiveBrowser.WaitUntilReady();
     
    var id = Manager.ActiveBrowser.Cookies.GetCookies("https://login.asp.net/login/signin.aspx?ReturnUrl=http://www.asp.net/get-started");
    Log.WriteLine(id["ASP.NET_SessionId"].Value);

    Let me know if you need further assistance on this.

    Regards,
    Plamen
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  3. Jet
    Jet avatar
    10 posts
    Member since:
    Oct 2012

    Posted 13 Nov 2012 Link to this post

    Thank you Plamen for your help.
    My answer is not detailed, this cookie is "httponly", so I couldn't get it by your approaches. Looks like there has no way to get httponly cookies.

  4. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 14 Nov 2012 Link to this post

    Hi Jet,

    When you tag a cookie with the HttpOnly flag, it tells the browser that this particular cookie should only be accessed by the server. Unfortunately this means that it cannot be accessed through the client side.

    All the best,
    Plamen
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  5. Jet
    Jet avatar
    10 posts
    Member since:
    Oct 2012

    Posted 15 Nov 2012 Link to this post


    I use another way to do my testing.
    Finally steps:
    1, send a request by WebRequest and get the session from the header of response
    2, set the cookie with the Manager.ActiveBrowser
    3, fake same name( the httponly) cookie

    Thanks.
  6. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 15 Nov 2012 Link to this post

    Hi Jet,

    I am glad to hear you found a workaround! Thanks for the update.

    Kind regards,
    Plamen
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
Back to Top