System.Net.Http.Headers.CookieHeaderValue.ToString C# (CSharp) Method

ToString() public method

public ToString ( ) : string
return string
        public override string ToString()
        {
            StringBuilder header = new StringBuilder();
            bool first = true;

            foreach (CookieState cookie in Cookies)
            {
                first = AppendSegment(header, first, cookie.ToString(), null);
            }

            if (Expires.HasValue)
            {
                first = AppendSegment(header, first, ExpiresToken, FormattingUtilities.DateToString(Expires.Value));
            }

            if (MaxAge.HasValue)
            {
                first = AppendSegment(header, first, MaxAgeToken, ((int)MaxAge.Value.TotalSeconds).ToString(NumberFormatInfo.InvariantInfo));
            }

            if (Domain != null)
            {
                first = AppendSegment(header, first, DomainToken, Domain);
            }

            if (Path != null)
            {
                first = AppendSegment(header, first, PathToken, Path);
            }

            if (Secure)
            {
                first = AppendSegment(header, first, SecureToken, null);
            }

            if (HttpOnly)
            {
                first = AppendSegment(header, first, HttpOnlyToken, null);
            }

            return header.ToString();
        }

Usage Example

Esempio n. 1
0
        public void CookieHeaderValue_Clone()
        {
            // Arrange
            NameValueCollection nvc = new NameValueCollection();

            nvc.Add("name", "value");
            CookieHeaderValue expectedValue = new CookieHeaderValue("cookie", nvc);

            expectedValue.Domain   = "domain";
            expectedValue.Expires  = DateTimeOffset.Now;
            expectedValue.MaxAge   = TimeSpan.FromDays(10);
            expectedValue.Path     = "path";
            expectedValue.HttpOnly = true;
            expectedValue.Secure   = true;

            // Act
            CookieHeaderValue actualValue = expectedValue.Clone() as CookieHeaderValue;

            // Assert
            Assert.Equal(expectedValue.ToString(), actualValue.ToString());
        }
All Usage Examples Of System.Net.Http.Headers.CookieHeaderValue::ToString