Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
From a.com/Search.aspx, open b.com/Contain.aspx page. Bypass the b.com/login.aspx page by API calling and open b.com/contain.aspx page.

a.com hosted by me and b.com manage by some external vendor.

What I have tried:

In a.com/Search.aspx page I written below code to call b.com login page api and able to successfully read the cookies values

var client = new RestClient("http://b.com/jjweb/app?username=jj_123&password=XXXX");
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;
else
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);
Response.Write("");
Response.Write("window.open('http://b.com/jjweb/Contain.aspx?page=ScreenHtml5&service=page&offset=0&quickrewindsec=-5&quickadvancesec=5','_blank')");
Response.Write("");


Now I want to open b.com/Contain.aspx page, in new window with cookies.
Please suggest any code or work around to archive this
Posted
Comments
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.
//LoginUrl='http://b.com/jjweb/app?username=jj_123&password=XXXX'
//PlayerUrl='http://b.com/jjweb/Contain.aspx?page=ScreenHtml5&service=page&offset=0&quickrewindsec=-5&quickadvancesec=5'
function doit(LoginUrl, PlayerUrl) {
jQuery.support.cors = true;
$.ajax({
url: LoginUrl,
type: 'GET',
dataType: 'script',
success: function (data) {
// alert(data);
window.open(PlayerUrl, '_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 http://b.com/jjweb/app?username=jj_123&password=XXXX&_=1512059288452\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