SetCookie() публичный Метод

public SetCookie ( string cookieList, string host ) : void
cookieList string
host string
Результат void
Пример #1
0
        private bool _CopyCookie(string name)
        {
            var cookie = CookieManager.GetCookies(DomainProvider.Eh.RootUri).SingleOrDefault(c => c.Name == name);

            if (cookie is null)
            {
                return(false);
            }
            cookie = new HttpCookie(cookie.Name, Domains.Ex, "/")
            {
                Expires  = cookie.Expires,
                HttpOnly = cookie.HttpOnly,
                Secure   = cookie.Secure,
                Value    = cookie.Value
            };
            CookieManager.SetCookie(cookie);
            return(true);
        }
Пример #2
0
        internal void ResetExCookie()
        {
            foreach (var item in CookieManager.GetCookies(DomainProvider.Ex.RootUri))
            {
                CookieManager.DeleteCookie(item);
            }

            foreach (var item in CookieManager.GetCookies(DomainProvider.Eh.RootUri).Where(isImportantCookie))
            {
                var cookie = new HttpCookie(item.Name, Domains.Ex, "/")
                {
                    Expires = item.Expires,
                    Value   = item.Value
                };
                CookieManager.SetCookie(cookie);
            }
            setDefaultCookies();
        }
Пример #3
0
        public void RestoreLogOnInfo(LogOnInfo info)
        {
            if (info is null)
            {
                throw new ArgumentNullException(nameof(info));
            }

            ClearLogOnInfo();
            foreach (var item in info.EhCookies)
            {
                CookieManager.SetCookie(item);
            }
            foreach (var item in info.ExCookies)
            {
                CookieManager.SetCookie(item);
            }
            _SetDefaultCookies();
        }
 private void ConfigureCookie(LoggedInUserViewModel user)
 {
     if (ModelState.IsValid)
     {
         _user          = _userCollection.GetUserByEmail(user.Email);
         user.UserId    = _user.Id;
         user.Role      = _user.Role;
         user.FirstName = _user.FirstName;
         user.LastName  = _user.LastName;
         List <object> newCookie = CookieManager.SetCookie(user);
         HttpContext.SignInAsync(
             CookieAuthenticationDefaults.AuthenticationScheme, (ClaimsPrincipal)newCookie[0],
             (AuthenticationProperties)newCookie[1]
             ).Wait();
         CookieManager.IsSignedIn = true;
         ViewData["SignedIn"]     = CookieManager.IsSignedIn;
     }
 }
Пример #5
0
        public ActionResult SignUp(SignUpVM vm)
        {
            if (!vm.IsAcknowledged)
            {
                ModelState.AddModelError("IsAcknowledged", "Please acknowledge the \"Totally Binding Commitment\".");
                return(SignUp(vm.ExchangeId));
            }

            var exchange = DAL.Context.Exchanges.Where(x => x.Id == vm.ExchangeId)
                           .Select(x => new { Exchange = x, IsSignedUp = x.SignUps.Any(s => s.ExchangeId == vm.ExchangeId && s.UserId == BifSessionData.Id) }).FirstOrDefault();

            ViewBag.MessageTitle = "Sign Up";
            if (exchange?.Exchange == null || DateTime.Now < exchange.Exchange.OpenDate)
            {
                ViewBag.Message = "This exchange is not yet open";
                return(View("Message"));
            }

            if (DateTime.Now >= exchange.Exchange.MatchDate)
            {
                ViewBag.Message = "This exchange is closed to new Sign Ups";
                return(View("Message"));
            }

            if (DateTime.Now > exchange.Exchange.CloseDate.AddDays(1))
            {
                ViewBag.Message = "This exchange is now closed";
                return(View("Message"));
            }

            bool success = doSignUp(exchange.Exchange, BifSessionData.Id, vm.Comment?.Trim(), out string message);

            if (!success)
            {
                ViewBag.Message = message;
                return(View("Message"));
            }

            CookieManager.SetCookie(new HttpCookie("exchangeId", exchange.Exchange.Id.ToString()));

            return(RedirectToAction("", ""));
        }
        public IActionResult EditOrder(int orderId, string name)
        {
            using (_context)
            {
                OrderManage order = new OrderManage(orderId, name);

                //Ensure order exists
                order.GetOrder(_context);
                if (order.order != null)
                {
                    //Sets up the basket with the list of items in the order.
                    Basket basket = new Basket();
                    basket.SetToOrder(_context, order.OrderId);
                    CookieManager.SetCookie("Basket", basket.GetSerialised(), Response);

                    //Set EditOrder Cookie: Holding the order id and name used to later save any changes.
                    CookieManager.SetCookie("EditOrder", order.GetSerialised(), Response);
                }

                return(RedirectToAction("Index"));
            }
        }
Пример #7
0
        public ActionResult Assign(string id)
        {
            int.TryParse(id, out int exchangeId);

            if (exchangeId == 0)
            {
                return(RedirectToAction("", "Administration"));
            }

            CookieManager.SetCookie(new HttpCookie("exchangeId", exchangeId.ToString()));

            IEnumerable <Assignment> matches = DAL.Context.Exchanges.Where(x => x.Id == exchangeId).Select(x =>
                                                                                                           x.SignUps
                                                                                                           .GroupJoin(x.Matches, s => s.UserId, m => m.SenderId,
                                                                                                                      (s, m) => new {
                SenderId       = s.UserId,
                SenderUsername = s.Profile.RedditUsername,
                SenderCity     = s.Profile.City,
                SenderState    = s.Profile.State,
                Match          = m.FirstOrDefault()
            }).Select(s => new Assignment {
                SenderId          = s.SenderId,
                SenderUsername    = s.SenderUsername,
                SenderLocation    = s.SenderCity + ", " + s.SenderState,
                RecipientId       = s.Match.RecipientId,
                RecipientUsername = s.Match.Recipient.Profile.RedditUsername,
                Carrier           = s.Match.Carrier,
                TrackingNo        = s.Match.TrackingNo
            }).OrderBy(s => s.SenderUsername)
                                                                                                           ).First();

            AssignVM vm = new AssignVM {
                ExchangeId  = exchangeId,
                Assignments = matches.ToList()
            };

            return(View(vm));
        }
Пример #8
0
        private async Task <string> OnSetCookieRequestAsync(Cookie cookie)
        {
            if (Control != null && Element != null)
            {
                var url = new Uri(Control.Url).Host;
                if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.LollipopMr1)
                {
                    CookieManager.Instance.SetCookie(url, cookie.ToString());
                    CookieManager.Instance.Flush();
                }
                else
                {
                    CookieSyncManager cookieSyncMngr = CookieSyncManager.CreateInstance(Context);
                    cookieSyncMngr.StartSync();
                    CookieManager cookieManager = CookieManager.Instance;
                    cookieManager.SetCookie(url, cookie.ToString());
                    cookieManager.Flush();
                }
            }

            var toReturn = await OnGetCookieRequestAsync(cookie.Name);

            return(toReturn);
        }
Пример #9
0
        public async Task <Stream> Transport(Stream request, Context context)
        {
            var clientContext = context as ClientContext;
            var uri           = clientContext.Uri;
            var timeout       = (int)clientContext.Timeout.TotalMilliseconds;
            var webRequest    = WebRequest.Create(uri) as HttpWebRequest;

            requests[webRequest] = null;
            try {
                webRequest.Method      = "POST";
                webRequest.ContentType = "application/hprose";
                if (Credentials != null)
                {
                    webRequest.Credentials = Credentials;
                }
                webRequest.Timeout     = timeout;
                webRequest.SendChunked = false;
                if (AcceptEncoding != null)
                {
                    webRequest.Headers.Set("Accept-Encoding", AcceptEncoding);
                }
                webRequest.ReadWriteTimeout = timeout;
                webRequest.ProtocolVersion  = HttpVersion.Version11;
                if (Proxy != null)
                {
                    webRequest.Proxy = Proxy;
                }
                webRequest.KeepAlive = KeepAlive;
                if (KeepAlive)
                {
                    webRequest.Headers.Set("Keep-Alive", KeepAliveTimeout.ToString());
                }
                webRequest.ConnectionGroupName = ConnectionGroupName;
                if (ClientCertificates != null)
                {
                    webRequest.ClientCertificates = ClientCertificates;
                }
                webRequest.Headers.Add(HttpRequestHeaders);
                if (context.Contains("httpRequestHeaders"))
                {
                    webRequest.Headers.Add(context["httpRequestHeaders"] as NameValueCollection);
                }
                webRequest.AllowWriteStreamBuffering = true;
                webRequest.Headers.Set("Cookie", cookieManager.GetCookie(uri.Host, uri.AbsolutePath, uri.Scheme == "https"));
                using (var ostream = await webRequest.GetRequestStreamAsync().ConfigureAwait(false)) {
                    await request.CopyToAsync(ostream).ConfigureAwait(false);

                    await ostream.FlushAsync().ConfigureAwait(false);
                }
                using (var webResponse = await webRequest.GetResponseAsync().ConfigureAwait(false) as HttpWebResponse) {
                    requests[webRequest]      = webResponse;
                    context["httpStatusCode"] = (int)webResponse.StatusCode;
                    context["httpStatusText"] = webResponse.StatusDescription;
                    if ((int)webResponse.StatusCode < 200 || (int)webResponse.StatusCode >= 300)
                    {
                        throw new Exception(((int)webResponse.StatusCode) + ":" + webResponse.StatusDescription);
                    }
                    var headers = new NameValueCollection(StringComparer.InvariantCultureIgnoreCase);
                    headers.Add(webResponse.Headers);
                    context["httpResponseHeaders"] = headers;
                    cookieManager.SetCookie(webResponse.Headers.GetValues("Set-Cookie"), uri.Host);
                    cookieManager.SetCookie(webResponse.Headers.GetValues("Set-Cookie2"), uri.Host);
                    int len      = (int)webResponse.ContentLength;
                    var response = (len > 0) ? new MemoryStream(len) : new MemoryStream();
                    using (var istream = webResponse.GetResponseStream()) {
                        string contentEncoding = webResponse.ContentEncoding.ToLower();
                        if (contentEncoding.IndexOf("deflate") > -1)
                        {
                            using (var deflateStream = new DeflateStream(istream, CompressionMode.Decompress)) {
                                await deflateStream.CopyToAsync(response).ConfigureAwait(false);
                            }
                        }
                        else if (contentEncoding.IndexOf("gzip") > -1)
                        {
                            using (var gzipStream = new GZipStream(istream, CompressionMode.Decompress)) {
                                await gzipStream.CopyToAsync(response).ConfigureAwait(false);
                            }
                        }
                        else
                        {
                            await istream.CopyToAsync(response).ConfigureAwait(false);
                        }
                    }
                    response.Position = 0;
                    return(response);
                }
            }
            finally {
                requests.Remove(webRequest, out var _);
            }
        }
Пример #10
0
        public async Task <Stream> Transport(Stream request, Context context)
        {
            Uri uri        = (context as ClientContext).Uri;
            var webRequest = WebRequest.Create(uri) as HttpWebRequest;

            requests[webRequest] = null;
            try {
                webRequest.Method      = "POST";
                webRequest.ContentType = "application/hprose";
                webRequest.Credentials = Credentials;
                webRequest.Timeout     = (int)Timeout.TotalMilliseconds;
                webRequest.SendChunked = false;
                if (AcceptEncoding != null)
                {
                    webRequest.Headers.Set("Accept-Encoding", AcceptEncoding);
                }
                webRequest.ReadWriteTimeout = (int)Timeout.TotalMilliseconds;
                webRequest.ProtocolVersion  = HttpVersion.Version11;
                if (Proxy != null)
                {
                    webRequest.Proxy = Proxy;
                }
                webRequest.KeepAlive = KeepAlive;
                if (KeepAlive)
                {
                    webRequest.Headers.Set("Keep-Alive", KeepAliveTimeout.ToString());
                }
                webRequest.ConnectionGroupName = ConnectionGroupName;
                if (ClientCertificates != null)
                {
                    webRequest.ClientCertificates = ClientCertificates;
                }
                foreach (var header in Headers)
                {
                    webRequest.Headers[header.Key] = header.Value;
                }
                webRequest.AllowWriteStreamBuffering = true;
                webRequest.Headers.Set("Cookie", cookieManager.GetCookie(uri.Host, uri.AbsolutePath, uri.Scheme == "https"));
                var ostream = await webRequest.GetRequestStreamAsync().ConfigureAwait(false);

                await request.CopyToAsync(ostream).ConfigureAwait(false);

                await ostream.FlushAsync().ConfigureAwait(false);

                ostream.Dispose();
                var webResponse = await webRequest.GetResponseAsync().ConfigureAwait(false) as HttpWebResponse;

                requests[webRequest] = webResponse;
                cookieManager.SetCookie(webResponse.Headers.GetValues("Set-Cookie"), uri.Host);
                cookieManager.SetCookie(webResponse.Headers.GetValues("Set-Cookie2"), uri.Host);
                var    istream         = webResponse.GetResponseStream();
                string contentEncoding = webResponse.ContentEncoding.ToLower();
                if (contentEncoding.IndexOf("deflate") > -1)
                {
                    istream = new DeflateStream(istream, CompressionMode.Decompress);
                }
                else if (contentEncoding.IndexOf("gzip") > -1)
                {
                    istream = new GZipStream(istream, CompressionMode.Decompress);
                }
                int len      = (int)webResponse.ContentLength;
                var response = (len > 0) ? new MemoryStream(len) : new MemoryStream();
                await istream.CopyToAsync(response).ConfigureAwait(false);

                istream.Dispose();
                webResponse.Close();
                return(response);
            }
            finally {
                requests.Remove(webRequest, out var _);
            }
        }
Пример #11
0
 private void SetCookie(Cookie cookie, string server)
 {
     _cookies.DeleteCookies($"https://www.{server}.darkorbit.com/", "dosid", null);
     _cookies.SetCookie($"https://www.{server}.darkorbit.com", cookie, null);
 }
Пример #12
0
 public static void SaveManagerCookie(Manager manager)
 {
     CookieManager.SetCookie(CookieConst.COOKIE_MANAMGER,
                             EncryptTools.EncryptDES(manager.GetManagerCookieString(), EncryptKey), DateTime.Now.AddDays(14));
 }