/// <summary> /// retrieve a shared remote session information /// </summary> /// <param name="guestId"></param> /// <returns></returns> private SharingInfo GetSharingInfo( Guid guestId) { SharingInfo sharingInfo = null; try { Application.Lock(); var sharedSessions = (IDictionary <Guid, SharingInfo>)Application[HttpApplicationStateVariables.SharedRemoteSessions.ToString()]; if (!sharedSessions.ContainsKey(guestId)) { connectError.InnerText = "Invalid sharing link"; } else { sharingInfo = sharedSessions[guestId]; if (sharingInfo.GuestInfo.Active) { connectError.InnerText = "The sharing link was already used"; sharingInfo = null; } else if (sharingInfo.RemoteSession.State != RemoteSessionState.Connected) { connectError.InnerText = "The session is not connected"; sharingInfo = null; } else if (sharingInfo.RemoteSession.ActiveGuests >= sharingInfo.RemoteSession.MaxActiveGuests) { connectError.InnerText = "The maximum number of active guests was reached for the session"; sharingInfo = null; } else { sharingInfo.HttpSession = Session; sharingInfo.RemoteSession.ActiveGuests++; sharingInfo.GuestInfo.Active = true; } } } catch (Exception exc) { System.Diagnostics.Trace.TraceError("Failed to retrieve the shared remote session for guest {0} ({1})", guestId, exc); } finally { Application.UnLock(); } return(sharingInfo); }
public Guid AddGuest(Guid connectionId, bool allowControl) { var guestId = Guid.Empty; try { HttpContext.Current.Application.Lock(); var remoteSessions = (IDictionary <Guid, RemoteSession>)HttpContext.Current.Application[HttpApplicationStateVariables.RemoteSessions.ToString()]; if (!remoteSessions.ContainsKey(connectionId)) { throw new Exception(string.Format("connection {0} not found", connectionId)); } else { var remoteSession = remoteSessions[connectionId]; if (remoteSession.State != RemoteSessionState.Connected) { throw new Exception(string.Format("remote session {0} is not connected", connectionId)); } else { var sharedSessions = (IDictionary <Guid, SharingInfo>)HttpContext.Current.Application[HttpApplicationStateVariables.SharedRemoteSessions.ToString()]; var sharingInfo = new SharingInfo { RemoteSession = remoteSession, GuestInfo = new GuestInfo { Id = Guid.NewGuid(), ConnectionId = remoteSession.Id, Control = allowControl } }; sharedSessions.Add(sharingInfo.GuestInfo.Id, sharingInfo); guestId = sharingInfo.GuestInfo.Id; } } } catch (Exception exc) { Trace.TraceError("Failed to add a guest for connection {0} ({1})", connectionId, exc); } finally { HttpContext.Current.Application.UnLock(); } return(guestId); }
/// <summary> /// create a shared session URL /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void CreateSessionUrlButtonClick( object sender, EventArgs e) { try { Application.Lock(); // create a new guest for the remote session var sharedSessions = (IDictionary <Guid, SharingInfo>)Application[HttpApplicationStateVariables.SharedRemoteSessions.ToString()]; var sharingInfo = new SharingInfo { RemoteSession = _remoteSession, GuestInfo = new GuestInfo { Id = Guid.NewGuid(), ConnectionId = _remoteSession.Id, Control = guestControl.Checked } }; sharedSessions.Add(sharingInfo.GuestInfo.Id, sharingInfo); bool isSecureConnection = Request.ServerVariables["HTTP_X_FORWARDED_PROTO"] != null?string.Equals(Request.ServerVariables["HTTP_X_FORWARDED_PROTO"], "https", StringComparison.OrdinalIgnoreCase) : string.Equals(Request.Url.Scheme, "https", StringComparison.OrdinalIgnoreCase); sessionUrl.Value = (isSecureConnection ? "https" : "http") + "://" + Request.Url.Host + (Request.Url.Port != 80 && Request.Url.Port != 443 ? ":" + Request.Url.Port : "") + Request.ApplicationPath + "/?gid=" + sharingInfo.GuestInfo.Id; } catch (ThreadAbortException) { // occurs because the response is ended after redirect } catch (Exception exc) { System.Diagnostics.Trace.TraceError("Failed to generate a session sharing url ({0})", exc); } finally { Application.UnLock(); } }