This is a migrated thread and some comments may be shown as answers.

How to get ASP.NET_SessionId via ActiveBrowser?

5 Answers 844 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jet
Top achievements
Rank 1
Jet asked on 25 Oct 2012, 06:42 AM
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?

5 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 30 Oct 2012, 01:51 PM
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
0
Jet
Top achievements
Rank 1
answered on 14 Nov 2012, 01:00 AM
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.

0
Plamen
Telerik team
answered on 14 Nov 2012, 09:31 AM
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
0
Jet
Top achievements
Rank 1
answered on 15 Nov 2012, 10:39 AM

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.
0
Plamen
Telerik team
answered on 15 Nov 2012, 12:43 PM
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
Tags
General Discussions
Asked by
Jet
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Jet
Top achievements
Rank 1
Share this question
or