private static string GetCookieValue(HttpCookie cookie, string cookieValName, bool encryptCookie) { string tmpOut = string.Empty; if (cookie != null) { if (cookie.Values[cookieValName] == null) return tmpOut; try { tmpOut = cookie.Values[cookieValName]; } catch { } if (encryptCookie && !string.IsNullOrWhiteSpace(tmpOut)) { Crypter crypt = new Crypter(); tmpOut = crypt.Decrypt(tmpOut); } return tmpOut; } else return tmpOut; }
public static string CookieValue(string cookieString, string cookieName, bool encryptCookie = true) { if (cookieString == null || cookieName == null) return null; string[] tmpData = cookieString.Split('&'); foreach (string item in tmpData) { if (item.StartsWith(cookieName + "=")) { if (encryptCookie) { Crypter crypt = new Crypter(); return crypt.Decrypt(TextHelper.FindP(item + "&", cookieName + "=", "&")); } else return TextHelper.FindP(item + "&", cookieName + "=", "&"); } } return null; }