Beispiel #1
0
        public static string GetSessionKey(this HttpContext context, Account account)
        {
            var sessionKey = string.Empty;

            if (context.Cache["SessionKey_" + account.AccountID] != null)
            {
                if (context.IsSessionKeyValid(account))
                {
                    sessionKey = context.Cache["SessionKey_" + account.AccountID].ToString();
                }
                else
                {
                    throw new InvalidSessionKeyException("Invalid session key for account : " + account.Username);
                }
            }
            else
            {
                sessionKey = account.Username + "-" + Guid.NewGuid() + "_" + DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss");
                context.Cache["SessionKey_" + account.AccountID] = sessionKey;
                context.AddAccount(sessionKey, account);
            }
            return(sessionKey);
        }
Beispiel #2
0
        public static string GetSessionKey(this HttpContext context, Account account)
        {
            var sessionKey = string.Empty;

            if (context.Session.Keys.FirstOrDefault(x => x == "SessionKey_" + account.AccountID) != null)
            {
                if (context.IsSessionKeyValid(account))
                {
                    sessionKey = context.Session.GetString("SessionKey_" + account.AccountID);
                }
                else
                {
                    throw new InvalidSessionKeyException("Invalid session key for account : " + account.Username);
                }
            }
            else
            {
                sessionKey = account.Username + "-" + Guid.NewGuid();
                context.Session.SetString("SessionKey_" + account.AccountID, sessionKey + "#" + DateTime.Now.ToString());
                context.AddAccount(sessionKey, account);
            }
            return(sessionKey);
        }