public static Session CreateSession(Guid identityId, AuthenticationTypeValues authenticationType) { var identity = EntityBase.ERPContext.Identity.Where(i => i.Id == identityId).FirstOrDefault(); if (identity == null) { throw new Exception("Identity was not found"); } // var session = new Session(); session.Id = Guid.NewGuid(); session.IdentityId = identityId; session.IPAddress = "-1"; session.AuthenticationToken = Guid.NewGuid(); session.AuthorizeTill = DateTime.Now.AddHours(3); session.AuthenticationType = authenticationType; session.CreatedBy = Guid.NewGuid(); session.CreatedDateTime = DateTime.Now; SetIdentityPrincipal(identity, session.AuthenticationType); session.SessionStatus = SessionStatusValues.LoggedIn; session.SaveAll(); return(session); }
private static void SetIdentityPrincipal(Identity identity, AuthenticationTypeValues authenticationType) { Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity(identity.Name, authenticationType.ToString()), null); }