Exemplo n.º 1
0
 /// <summary>
 /// set the value
 /// </summary>
 /// <param name="key">key</param>
 /// <param name="value">value</param>
 /// <param name="expireTime"></param>
 public void Set(string key, object value, int?expireTime = default(int?))
 {
     if (value is string)
     {
         _cookie.Set(key, value.ToString(), expireTime);
     }
     else
     {
         _cookie.Set(key, JsonConvert.SerializeObject(value), expireTime);
     }
 }
Exemplo n.º 2
0
 public void Remove(string key)
 {
     if (!this.deletedCookies.Any(a => a == key))
     {
         this.deletedCookies.Add(key);
         _cookie.Remove(key);
         //actually removes the cookie
         _cookie.Set(key, "", new CookieOptions {
             Expires = DateTime.Now.AddMinutes(-20)
         });
     }
 }
        public void SetCookie(string name, string value)
        {
            string keystr = _cookie.Get(name);

            if (!string.IsNullOrWhiteSpace(name))
            {
                _cookie.Set(name, value, new CookieOptions()
                {
                    HttpOnly = true, Expires = DateTime.Now.AddDays(1)
                });
            }
        }
Exemplo n.º 4
0
        public IActionResult SigninWithDiscord([FromQuery] string code)
        {
            string sessionId = _cookie.Get("ReportSession");
            var    viewModel = new ReportWebApp.Models.ViewModels.Discord.Signin(this.discordService, code, this.authService, sessionId);

            _cookie.Set("ReportSession", viewModel.NewSessionCookie, new CookieOptions()
            {
                HttpOnly = true, Expires = DateTime.UtcNow.AddDays(13)
            });

            return(View(viewModel));
        }
Exemplo n.º 5
0
        public void Cookie_SetCookieTest()
        {
            //TODO getting null value of data protector
            ICookie cookie           = setupICookie();
            string  expecteSetCookie = cookieResponseHeaders["cookiemanager_1"];

            cookie.Set("cookiemanager_1", "test1234", new CookieOptions()
            {
                Expires = new DateTimeOffset(2020, 09, 02, 23, 19, 18, TimeSpan.Zero)
            });
            var actualString = httpContext.Response.Headers["cookiemanager_1"];

            Assert.AreEqual(expecteSetCookie, actualString);
        }
Exemplo n.º 6
0
 public IActionResult DoLogin(string spusername, string sppassword)
 {
     if (_authenticationService.TryLoginCredentials(spusername, sppassword))
     {
         var        viewModel = new DoLoginViewModel();
         WebSession session   = _authenticationService.CreateWebSession(spusername);
         viewModel.Message = "Created new web session valid until " + session.Expiry.ToShortDateString();
         _cookie.Set("ReportSession", session.SessionCookie, new CookieOptions()
         {
             HttpOnly = true, Expires = DateTime.UtcNow.AddDays(13)
         });
         return(View(viewModel));
     }
     return(RedirectToAction("Login", "Account"));
 }
 /// <summary>
 /// set the value
 /// </summary>
 /// <param name="key">key</param>
 /// <param name="value">value</param>
 /// <param name="expireTime"></param>
 public void Set(string key, object value, int?expireTime = default(int?))
 {
     _cookie.Set(key, JsonConvert.SerializeObject(value), expireTime);
 }