AddHeader() public static method

public static AddHeader ( string[]>.this headers, string name, string value ) : string[]>.IDictionary
headers string[]>.this
name string
value string
return string[]>.IDictionary
Example #1
0
        public Response SetCookie(string key, Cookie cookie)
        {
            var domainHasValue  = !string.IsNullOrEmpty(cookie.Domain);
            var pathHasValue    = !string.IsNullOrEmpty(cookie.Path);
            var expiresHasValue = cookie.Expires.HasValue;

            var setCookieValue = string.Concat(
                Uri.EscapeDataString(key),
                "=",
                Uri.EscapeDataString(cookie.Value ?? ""),
                !domainHasValue ? null : "; domain=",
                !domainHasValue ? null : cookie.Domain,
                !pathHasValue ? null : "; path=",
                !pathHasValue ? null : cookie.Path,
                !expiresHasValue ? null : "; expires=",
                !expiresHasValue ? null : cookie.Expires.Value.ToString("ddd, dd-MMM-yyyy HH:mm:ss ") + "GMT",
                !cookie.Secure ? null : "; secure",
                !cookie.HttpOnly ? null : "; HttpOnly"
                );

            Headers.AddHeader("Set-Cookie", setCookieValue);
            return(this);
        }
Example #2
0
 public Response SetCookie(string key, string value)
 {
     Headers.AddHeader("Set-Cookie", Uri.EscapeDataString(key) + "=" + Uri.EscapeDataString(value) + "; path=/");
     return(this);
 }