Exemple #1
0
        /// <summary>
        ///     Adds the specified token and <see cref="ICaptchaValue" /> to the storage.
        /// </summary>
        /// <param name="captchaPair">
        ///     The specified <see cref="KeyValuePair{TKey,TValue}" />
        /// </param>
        public virtual void Add(KeyValuePair <string, ICaptchaValue> captchaPair)
        {
            Validate.ArgumentNotNull(captchaPair, "captchaPair");
            Validate.ArgumentNotNull(captchaPair.Value, "captchaPair");
            string     drawingKey        = CookieName + DrawingKey;
            HttpCookie httpCookieDrawing = HttpContext.Current.Request.Cookies[drawingKey] ??
                                           new HttpCookie(drawingKey);
            HttpCookie httpCookie = HttpContext.Current.Request.Cookies[CookieName] ??
                                    new HttpCookie(CookieName);

            httpCookie.Expires  = httpCookieDrawing.Expires = DateTime.Now.AddMinutes(ExpiresMinutes);
            httpCookie.HttpOnly = httpCookieDrawing.HttpOnly = true;

            string serialize = Serialize(captchaPair.Value);

            ClearCookieIfNeed(httpCookie);
            ClearCookieIfNeed(httpCookieDrawing);

            httpCookie.Values.Add(captchaPair.Key, serialize);
            httpCookieDrawing.Values.Add(captchaPair.Key, serialize);

            HttpContext.Current.Response.Cookies.Add(httpCookie);
            HttpContext.Current.Response.Cookies.Add(httpCookieDrawing);
        }