protected void Session_Start(object sender, EventArgs e) { string Message; try { WindowsIdentity CurrentIdentity = WindowsIdentity.GetCurrent(); string strUser; WindowsIdentity CallerWindowsIdentity = HttpContext.Current.User.Identity as WindowsIdentity; if (CallerWindowsIdentity == null) { strUser = "******"; } else if (CallerWindowsIdentity.IsAuthenticated) { strUser = CallerWindowsIdentity.Name; } else { strUser = "******"; } Message = " Connected as " + strUser + " ( " + CurrentIdentity.Name + " )"; } catch (Exception ex) { Message = " Failed to get identity data : " + ex.Message; } // Create an EventLog instance and assign its source. EventLog appLog = new EventLog(); appLog.Source = "TroposWebClient"; appLog.WriteEntry("TroposUIAdmin.Global.Session_Start" + Environment.NewLine + "Starting session" + Environment.NewLine + Message, EventLogEntryType.Information); UserContext context = null; string TroposLogin = HttpContext.Current.Request.QueryString["TroposLogin"]; if (!string.IsNullOrEmpty(TroposLogin)) { string TroposLoginClear = TroposEncryption.DecryptString(TroposLogin); string[] LoginDetails = TroposLoginClear.Split(new char[] { ':' }); string TroposServer = LoginDetails[0]; string TroposDatabase = LoginDetails[1]; string TroposIdentity = LoginDetails[2]; string TroposPassword = LoginDetails[3]; bool WindowsAuthentication = bool.Parse(LoginDetails[4]); string TroposBusiness = ""; try { TroposBusiness = LoginDetails[5]; } catch { // No business code passed - just ignore it. } int TniSessionId = -1; if (LoginDetails.GetUpperBound(0) >= 6) { TniSessionId = int.Parse(LoginDetails[6], CultureInfo.InvariantCulture); } if (WindowsAuthentication) { WindowsImpersonationContext Ctx = null; if (HttpContext.Current.User.Identity.IsAuthenticated) { context = new UserContext(TroposServer, TroposDatabase, TroposBusiness); WindowsIdentity WinId = (WindowsIdentity)HttpContext.Current.User.Identity; Ctx = WinId.Impersonate(); } else { throw new Exception("Windows authentication not set up correctly"); } try { if (TniSessionId >= 0) { context.LoadShared(Session, TniSessionId); } else { context.Load(Session); } } finally { if (Ctx != null) { Ctx.Undo(); } } } else { context = new UserContext(TroposServer, TroposDatabase, TroposIdentity, TroposPassword, TroposBusiness); if (TniSessionId >= 0) { context.LoadShared(Session, TniSessionId); } else { context.Load(Session); } } context.ParentUrlPrefix = HttpContext.Current.Request.QueryString["ParentUrlPrefix"]; } else { CustomIdentity ident = User.Identity as CustomIdentity; if (ident != null) { context = new UserContext(ident.TroposServer, ident.TroposDatabase, ident.TroposUserName, ident.TroposPassword, ident.TroposBusiness, ident.IsTroposManager); context.ParentUrlPrefix = ident.ParentUrlPrefix; context.Load(Session); } } }
protected void Page_Load(object sender, EventArgs e) { phMenu.Controls.Clear(); phMenu.Controls.Add(UserContext.Menus); // We have been called from a Tropos User Interface instance which has given us the login credentails. // Check that the credentials we have been passed are the same as those in the current context. // If not - something is seriously wrong so do not allow the user to continue. TroposLogin = HttpContext.Current.Request.QueryString["TroposLogin"]; if (!string.IsNullOrEmpty(TroposLogin)) { string TroposLoginClear = TroposEncryption.DecryptString(TroposLogin); string[] LoginDetails = TroposLoginClear.Split(new char[] { ':' }); string TroposServer = LoginDetails[0]; string TroposDatabase = LoginDetails[1]; string TroposIdentity = LoginDetails[2]; bool WindowsAuthentication = bool.Parse(LoginDetails[4]); if (this.UserContext.TroposServer == TroposServer && this.UserContext.TroposDatabase == TroposDatabase && this.UserContext.TroposIdentity == TroposIdentity && this.UserContext.WindowsAuthentication == WindowsAuthentication) { } else { Session.Abandon(); throw new TroposConnectionException("Tropos login credentials from request do not match current Session", TroposUI.Common.DataUpdater.TroposError.Other, System.Diagnostics.EventLogEntryType.Error); } } TroposLogin = TroposEncryption.EncryptString( this.UserContext.TroposServer + ":" + this.UserContext.TroposDatabase + ":" + this.UserContext.TroposIdentity + ":" + (string.IsNullOrEmpty(UserContext.TroposPassword) ? "empty" : UserContext.TroposPassword) + ":" + this.UserContext.WindowsAuthentication.ToString() + ":" + this.UserContext.TroposBusiness + ":" + this.UserContext.TroposSession.SessionKey.TniSessionId); string Script = "var TroposLogin='******';"; Script += "var ParentUrlPrefix='" + this.UserContext.ParentUrlPrefix + "';"; ScriptManager.RegisterStartupScript(this, this.GetType(), "TroposLogin", Script, true); if (QC != null) { QC.Attributes.Add("onKeyPress", "doQuickCode('" + hdnQCEvent.ClientID + "',event)"); QC.TabIndex = UserContext.QUICK_CODE_TAB_INDEX; } if (Session["menuStateArray"] != null) { if (!string.IsNullOrEmpty(menuStateControl.Value)) { Session["menuStateArray"] = menuStateControl.Value; } else { menuStateControl.Value = Session["menuStateArray"].ToString(); } } if (!Page.IsPostBack) { SetQuickCode(); } if (!TWCScriptManager.IsInAsyncPostBack) { bool menuAutoOpen = false; bool menuAutoExpand = false; HttpCookie MenuCookie = Request.Cookies["TroposMenu"]; if (MenuCookie != null) { try { if (!bool.TryParse(MenuCookie.Values["AutoOpen"], out menuAutoOpen)) { menuAutoOpen = false; } if (!bool.TryParse(MenuCookie.Values["AutoExpand"], out menuAutoExpand)) { menuAutoExpand = false; } } catch (Exception) { } } menuSingleOption.Checked = menuAutoOpen; menuAutoExpandOption.Checked = menuAutoExpand; UP_SingleMenu.Update(); } if (new Version(Helpers.TroposUIVersion(this.UserContext)) < new Version("1.10.0")) { menuSingleOption.Style["display"] = "inline"; menuAutoExpandOption.Style["display"] = "inline"; } }