예제 #1
0
        private string GetCookieValue(HttpContext context, string cookieName, bool isEncrypted)
        {
            try
            {
                var sessionCookie  = context.Request.Cookies[cookieName];
                var hasCookieValue = HasCookieValue(context, cookieName, isEncrypted);

                if (!hasCookieValue)
                {
                    return(null);
                }

                var sessionCookieUrlDecoded = HttpUtility.UrlDecode(sessionCookie?.Value);
                if (!isEncrypted)
                {
                    return(sessionCookieUrlDecoded);
                }

                var decryptedValue = SecurityEncryption.Decrypt(sessionCookieUrlDecoded);
                return(decryptedValue);
            }
            catch
            {
                return(null);
            }
        }
예제 #2
0
        private static bool HasCookieValue(HttpContext context, string cookieName, bool checkEncryptedValue = false)
        {
            var sessionCookie = context.Request.Cookies[cookieName];

            var isNull = sessionCookie?.Value == null;

            if (isNull)
            {
                return(false);
            }

            if (!checkEncryptedValue)
            {
                return(true);
            }

            try
            {
                var sessionCookieValue   = HttpUtility.UrlDecode(sessionCookie.Value);
                var decryptedCookieValue = SecurityEncryption.Decrypt(sessionCookieValue);

                return(decryptedCookieValue != null);
            }
            catch
            {
                return(false);
            }
        }
예제 #3
0
        private Tuple <string, string> GetCookie2(HttpContext context)
        {
            var cookie = context.Request.Cookies[SessionCookieName];

            if (cookie?.Value == null)
            {
                return(null);
            }

            try
            {
                var urlDecodeCookieValue = HttpUtility.UrlDecode(cookie.Value);
                var decryptedCookieValue = SecurityEncryption.Decrypt(urlDecodeCookieValue);

                return(decryptedCookieValue != null ? new Tuple <string, string>(urlDecodeCookieValue, decryptedCookieValue) : null);
            }
            catch
            {
                return(null);
            }
        }