private void Session_Start(object sender, EventArgs e) { if (!_isAuthenticated) { var authenticationManager = new AuthenticationManagerOnPremise(); authenticationManager.Login(); var recordId = Guid.NewGuid(); var context = new Context { SessionId = HttpContext.Current.Session.SessionID, ApplicationUserId = "ADMIN", Company = "SAMLTD", ProductUserId = recordId, TenantId = recordId, TenantAlias = Sage.CA.SBS.ERP.Sage300.Common.Web.AreaConstants.Core.OnPremiseTenantAlias, ApplicationType = ApplicationType.WebApplication, Language = "en", ScreenName = "None", Container = BootstrapTaskManager.Container }; authenticationManager.LoginResult(HttpContext.Current.Session.SessionID, "SAMLTD", "ADMIN", "ADMIN", BootstrapTaskManager.Container, context); _isAuthenticated = true; //Redirect to the last generated page var fileUrlPath = Path.Combine(Server.MapPath("~"), "PageUrl.txt"); if (File.Exists(fileUrlPath)) { var url = File.ReadAllText(fileUrlPath).Trim(); url = "http://" + HttpContext.Current.Request.ServerVariables["HTTP_HOST"] + url; Response.Redirect(url); } } }
private void Session_Start(object sender, EventArgs e) { if (!_isAuthenticated) { var authenticationManager = new AuthenticationManagerOnPremise(); authenticationManager.Login(); var recordId = Guid.NewGuid(); var context = new Context { AspNetSessionId = HttpContext.Current.Session.SessionID, ApplicationUserId = "ADMIN", Company = "SAMLTD", ProductUserId = recordId, TenantId = recordId, TenantAlias = Sage.CA.SBS.ERP.Sage300.Common.Web.AreaConstants.Core.OnPremiseTenantAlias, ApplicationType = ApplicationType.WebApplication, Language = "en", Container = BootstrapTaskManager.Container, ScreenContext = new ScreenContext() }; var sessionId = $"{context.ApplicationUserId.Trim()}-{context.Company.Trim()}"; context.ScreenContext.ScreenName = "None"; context.SessionId = Encoding.UTF8.Base64Encode(sessionId); var companies = new List <Organization> { new Organization() { Id = "SAMLTD", Name = "SAMLTD", System = "Company", IsSecurityEnabled = false, SystemId = "SAMSYS" } }; authenticationManager.LoginResult("SAMLTD", "ADMIN", "ADMIN", BootstrapTaskManager.Container, context, companies); _isAuthenticated = true; //Redirect to the last generated page var fileUrlPath = Path.Combine(Server.MapPath("~"), "PageUrl.txt"); if (File.Exists(fileUrlPath)) { var url = File.ReadAllText(fileUrlPath).Trim(); url = HttpContext.Current.Request.Url.AbsoluteUri + string.Format(url, context.SessionId); Response.Redirect(url); } } }
/// <summary> /// Login Action /// </summary> /// <param name="sender">Sender</param> /// <param name="e">Event</param> protected void LoginButton_Click(object sender, EventArgs e) { // Force case and trim var user = UserText.Text.ToUpper().Trim(); var pwd = PwdText.Text.ToUpper().Trim(); var company = CompanyText.Text.ToUpper().Trim(); var system = SystemText.Text.ToUpper().Trim(); var version = VersionText.Text.ToUpper().Trim(); var redirect = "PageUrl.txt"; var login = "******"; // Validate credentials early to avoid having real Sage 300 dialog show if (!ValidCredentials(user, pwd, company, version)) { return; } // Locals var authenticationManager = new AuthenticationManagerOnPremise(); authenticationManager.Login(); var recordId = Guid.NewGuid(); // Save cookie before proceeding SaveCookie(user, company, system, version); // Fill context object var context = new Context { AspNetSessionId = HttpContext.Current.Session.SessionID, ApplicationUserId = user, Company = company, ProductUserId = recordId, TenantId = recordId, TenantAlias = Sage.CA.SBS.ERP.Sage300.Common.Web.AreaConstants.Core.OnPremiseTenantAlias, ApplicationType = ApplicationType.WebApplication, Language = "en", ScreenContext = new ScreenContext(), ScreenName = "None", Container = BootstrapTaskManager.Container }; // Set session var sessionId = $"{context.ApplicationUserId.Trim()}-{context.Company.Trim()}"; context.ScreenContext.ScreenName = "None"; context.SessionId = Encoding.UTF8.Base64Encode(sessionId); // Set default company information var companies = new List <Sage.CA.SBS.ERP.Sage300.Common.Models.Organization> { new Sage.CA.SBS.ERP.Sage300.Common.Models.Organization() { Id = company, Name = company, SystemId = system, System = system, IsSecurityEnabled = false } }; // Perform the login authenticationManager.LoginResult(company, user, pwd, BootstrapTaskManager.Container, context, companies); // Redirect to the last generated page var fileUrlPath = Path.Combine(Server.MapPath("~"), redirect); if (File.Exists(fileUrlPath)) { var url = File.ReadAllText(fileUrlPath).Trim(); url = HttpContext.Current.Request.Url.AbsoluteUri.Replace(login, string.Empty) + string.Format(url, context.SessionId); Response.Redirect(url); } }