Ejemplo n.º 1
0
		static HttpCookie BuildCookie(Cookie cookie)
		{
			var c = new HttpCookie();
			c.Name = cookie.Name;
			c.Value = cookie.Value;
			c.Domain = cookie.Domain;
			c.Expiration = cookie.Expires;
			c.Secure = cookie.Secure;
			c.Value = cookie.Value;
			c.HttpOnly = cookie.HttpOnly;
			return c;
		}
Ejemplo n.º 2
0
		void SaveInCookie(MvcContext context, User user, bool isPersistent)
		{
			var cookie = new HttpCookie();
			cookie.Name = CookieName;
			cookie.Value = UrlUtil.UrlEncode(user.SessionId); // solo mandar caracteres válidos a la cookie
			cookie.HttpOnly = true;

			// si es persistente especifica la fecha, si no dura lo que la sesión del navegador.
			if (isPersistent)
			{
				cookie.Expiration = DateTime.UtcNow.AddDays(CookieExpirationDays);
			}

			context.ResponseCookies.Add(CookieName, cookie);
		}
Ejemplo n.º 3
0
		static string GetHeaderValue(HttpCookie cookie)
		{
			var sb = new StringBuilder();			
			sb.AppendFormat("{0}={1};path={2}", cookie.Name, cookie.Value, "/");

			if (cookie.Expiration.HasValue)
			{
				sb.AppendFormat(";expires={0}", cookie.Expiration.Value.ToString("R"));
			}

			var domain = cookie.Domain;
			if (domain != null)
			{
				sb.AppendFormat(";domain={0}", domain);
			}

			if (cookie.Secure)
			{
				sb.Append(";Secure");
			}

			if (cookie.HttpOnly)
			{
				sb.Append(";HttpOnly");
			}

			return sb.ToString();
		}