Click here to Skip to main content
14,921,745 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
From, open page. Bypass the page by API calling and open page. hosted by me and manage by some external vendor.

What I have tried:

In page I written below code to call login page api and able to successfully read the cookies values

var client = new RestClient("");
var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);
IList<restresponsecookie> res = response.Cookies;

string JSessionID = string.Empty;
string JJSessionID = string.Empty;
string JJAccessToken = string.Empty;

JSessionID = response.ResponseUri.AbsolutePath.Split(';')[1].Split('=')[1].ToString();

foreach (RestResponseCookie item in res)
if (item.Name.ToUpper() == "JJSESSIONID")
JJSessionID = item.Value;
JJAccessToken = item.Value;

System.Diagnostics.Debug.WriteLine("JSESSIONID={0}; JJSESSIONID={1}; JJACCESSTOKEN={2}", JSessionID, JJSessionID, JAccessToken);

Response.Cookies["JSESSIONID"].Value = JSessionID;
Response.Cookies["JSESSIONID"].Expires = DateTime.Now.AddMinutes(1);
Response.Cookies["JJSESSIONID"].Value = JJSessionID;
Response.Cookies["JJSESSIONID"].Expires = DateTime.Now.AddMinutes(1);
Response.Cookies["JJACCESSTOKEN"].Value = JJAccessToken;
Response.Cookies["JJACCESSTOKEN"].Expires = DateTime.Now.AddMinutes(1);

Now I want to open page, in new window with cookies.
Please suggest any code or work around to archive this
F-ES Sitecore 28-Nov-17 5:12am
You're not going to be able to do this for security reasons mainly. When you access the page programatically you control the "cookie container", you get to say what cookeis are sent and you get to control what happens to cookies that are written back. If you want the page to open in the user's browser then the browser becomes the cookie container and you no longer have control.

It would be very dangerous if you could control the user's cookies for other sites from your server-code. You'll need to look into implementing a single sign on as that is the solution to these problems but it isn't trivial and it means you need to control both sites.
PrakashPaul 1-Dec-17 8:10am
I found another way for doing this, client side calling, but problem is it is failing in IE with exception, but worked in chrome and Firefox.
function doit(LoginUrl, PlayerUrl) { = true;
url: LoginUrl,
type: 'GET',
dataType: 'script',
success: function (data) {
// alert(data);, '_blank');
error: function (x, y, z) {
alert(x + '\n' + y + '\n' + z);

any hints why it is not worked in IE, IE exception is "JavaScript critical error at line 1, in\n\nSCRIPT1002: Syntax error"

Karthik_Mahalingam 5-Dec-17 23:49pm
use  Reply  button, to post Comments/query to the user, so that the user gets notified and responds to your text.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900