public void Add(Cookie cookie) { Uri uri; if (cookie == null) { throw new ArgumentNullException("cookie"); } if (cookie.Domain.Length == 0) { throw new ArgumentException(SR.GetString("net_emptystringcall"), "cookie.Domain"); } StringBuilder builder = new StringBuilder(); builder.Append(cookie.Secure ? Uri.UriSchemeHttps : Uri.UriSchemeHttp).Append(Uri.SchemeDelimiter); if (!cookie.DomainImplicit && (cookie.Domain[0] == '.')) { builder.Append("0"); } builder.Append(cookie.Domain); if (cookie.PortList != null) { builder.Append(":").Append(cookie.PortList[0]); } builder.Append(cookie.Path); if (!Uri.TryCreate(builder.ToString(), UriKind.Absolute, out uri)) { throw new CookieException(SR.GetString("net_cookie_attribute", new object[] { "Domain", cookie.Domain })); } Cookie cookie2 = cookie.Clone(); cookie2.VerifySetDefaults(cookie2.Variant, uri, this.IsLocalDomain(uri.Host), this.m_fqdnMyDomain, true, true); this.Add(cookie2, true); }
public void Add(Uri uri, Cookie cookie) { ArgumentNullException.ThrowIfNull(uri); ArgumentNullException.ThrowIfNull(cookie); Cookie new_cookie = cookie.Clone(); new_cookie.VerifySetDefaults(new_cookie.Variant, uri, IsLocalDomain(uri.Host), m_fqdnMyDomain, true, true); Add(new_cookie, true); }
// This method will construct a faked URI: the Domain property is required for param. public void Add(Cookie cookie) { if (cookie == null) { throw new ArgumentNullException(nameof(cookie)); } if (cookie.Domain.Length == 0) { throw new ArgumentException( SR.Format(SR.net_emptystringcall, nameof(cookie) + "." + nameof(cookie.Domain)), nameof(cookie) + "." + nameof(cookie.Domain)); } Uri uri; var uriSb = new StringBuilder(); // We cannot add an invalid cookie into the container. // Trying to prepare Uri for the cookie verification. uriSb.Append(cookie.Secure ? UriScheme.Https : UriScheme.Http).Append(UriScheme.SchemeDelimiter); // If the original cookie has an explicitly set domain, copy it over to the new cookie. if (!cookie.DomainImplicit) { if (cookie.Domain[0] == '.') { uriSb.Append("0"); // URI cctor should consume this faked host. } } uriSb.Append(cookie.Domain); // Either keep Port as implicit or set it according to original cookie. if (cookie.PortList != null) { uriSb.Append(":").Append(cookie.PortList[0]); } // Path must be present, set to root by default. uriSb.Append(cookie.Path); if (!Uri.TryCreate(uriSb.ToString(), UriKind.Absolute, out uri)) { throw new CookieException(SR.Format(SR.net_cookie_attribute, "Domain", cookie.Domain)); } // We don't know cookie verification status, so re-create the cookie and verify it. Cookie new_cookie = cookie.Clone(); new_cookie.VerifySetDefaults(new_cookie.Variant, uri, IsLocalDomain(uri.Host), m_fqdnMyDomain, true, true); Add(new_cookie, true); }
public void Add(Uri uri, Cookie cookie) { if (uri == null) { throw new ArgumentNullException("uri"); } if (cookie == null) { throw new ArgumentNullException("cookie"); } Cookie cookie2 = cookie.Clone(); cookie2.VerifySetDefaults(cookie2.Variant, uri, this.IsLocalDomain(uri.Host), this.m_fqdnMyDomain, true, true); this.Add(cookie2, true); }
public void Add(Uri uri, Cookie cookie) { if (uri == null) { throw new ArgumentNullException(nameof(uri)); } if (cookie == null) { throw new ArgumentNullException(nameof(cookie)); } Cookie new_cookie = cookie.Clone(); new_cookie.VerifySetDefaults(new_cookie.Variant, uri, IsLocalDomain(uri.Host), m_fqdnMyDomain, true, true); Add(new_cookie, true); }
public void SetCookie(Cookie cookie) { if (cookie == null) { throw new ArgumentNullException("cookie"); } Cookie new_cookie = cookie.Clone(); int added = Cookies.InternalAdd(new_cookie, true); if (Logging.On) { Logging.PrintInfo(Logging.HttpListener, this, "SetCookie", " cookie#" + ValidationHelper.HashString(cookie)); } if (added != 1) { // cookie already existed and couldn't be replaced throw new ArgumentException(SR.GetString(SR.net_cookie_exists), "cookie"); } }
/// <summary> /// Добавляет <see cref="T:System.Net.Cookie"/> в <see cref="T:System.Net.CookieContainer"/>.В этом методе используется домен из класса <see cref="T:System.Net.Cookie"/> для определения доменной коллекции, которую требуется связать с <see cref="T:System.Net.Cookie"/>. /// </summary> /// <param name="cookie">Объект <see cref="T:System.Net.Cookie"/>, добавляемый в <see cref="T:System.Net.CookieContainer"/>. </param><exception cref="T:System.ArgumentNullException">Значение параметра <paramref name="cookie"/> — null. </exception><exception cref="T:System.ArgumentException">Домен для <paramref name="cookie"/> равен null или пустой строке (""). </exception><exception cref="T:System.Net.CookieException">Значение <paramref name="cookie"/> больше, чем значение <paramref name="maxCookieSize"/>–или– домен для <paramref name="cookie"/> не является допустимым URI. </exception><PermissionSet><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/></PermissionSet> public void Add(Cookie cookie) { if (cookie == null) { throw new ArgumentNullException("cookie"); } if (cookie.Domain.Length == 0) { throw new ArgumentException(SR.GetString("net_emptystringcall"), "cookie.Domain"); } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(cookie.Secure ? Uri.UriSchemeHttps : Uri.UriSchemeHttp).Append(Uri.SchemeDelimiter); if (!cookie.DomainImplicit && (int)cookie.Domain[0] == 46) { stringBuilder.Append("0"); } stringBuilder.Append(cookie.Domain); if (cookie.PortList != null) { stringBuilder.Append(":").Append(cookie.PortList[0]); } stringBuilder.Append(cookie.Path); Uri result; if (!Uri.TryCreate(((object)stringBuilder).ToString(), UriKind.Absolute, out result)) { throw new CookieException(SR.GetString("net_cookie_attribute", (object)"Domain", (object)cookie.Domain)); } else { Cookie cookie1 = cookie.Clone(); cookie1.VerifySetDefaults(cookie1.Variant, result, this.IsLocalDomain(result.Host), this.m_fqdnMyDomain, true, true); this.Add(cookie1, true); } }
public void SetCookie(Cookie cookie) { if (cookie==null) { throw new ArgumentNullException("cookie"); } Cookie new_cookie = cookie.Clone(); int added = Cookies.InternalAdd(new_cookie, true); if(Logging.On)Logging.PrintInfo(Logging.HttpListener, this, "SetCookie", " cookie#"+ValidationHelper.HashString(cookie)); if (added!=1) { // cookie already existed and couldn't be replaced throw new ArgumentException(SR.GetString(SR.net_cookie_exists), "cookie"); } }
public void Add(Uri uri, Cookie cookie) { if (uri == null) { throw new ArgumentNullException("uri"); } if (cookie == null) { throw new ArgumentNullException("cookie"); } Cookie new_cookie = cookie.Clone(); new_cookie.VerifySetDefaults(new_cookie.Variant, uri, IsLocalDomain(uri.Host), _fqdnMyDomain, true, true); Add(new_cookie, true); }
// This method will construct a faked URI: the Domain property is required for param. public void Add(Cookie cookie) { if (cookie == null) { throw new ArgumentNullException("cookie"); } if (cookie.Domain.Length == 0) { throw new ArgumentException(SR.net_emptystringcall, "cookie.Domain"); } Uri uri; StringBuilder uriSb = new StringBuilder(); // We cannot add an invalid cookie into the container. // Trying to prepare Uri for the cookie verification. uriSb.Append(cookie.Secure ? UriScheme.Https : UriScheme.Http).Append(UriScheme.SchemeDelimiter); // If the original cookie has an explicitly set domain, copy it over to the new cookie. if (!cookie.DomainImplicit) { if (cookie.Domain[0] == '.') { uriSb.Append("0"); // URI cctor should consume this faked host. } } uriSb.Append(cookie.Domain); // Either keep Port as implicit or set it according to original cookie. if (cookie.PortList != null) { uriSb.Append(":").Append(cookie.PortList[0]); } // Path must be present, set to root by default. uriSb.Append(cookie.Path); if (!Uri.TryCreate(uriSb.ToString(), UriKind.Absolute, out uri)) throw new CookieException(SR.Format(SR.net_cookie_attribute, "Domain", cookie.Domain)); // We don't know cookie verification status, so re-create the cookie and verify it. Cookie new_cookie = cookie.Clone(); new_cookie.VerifySetDefaults(new_cookie.Variant, uri, IsLocalDomain(uri.Host), _fqdnMyDomain, true, true); Add(new_cookie, true); }
/// <summary> /// Добавляет <see cref="T:System.Net.Cookie"/> в <see cref="T:System.Net.CookieContainer"/>.В этом методе используется домен из класса <see cref="T:System.Net.Cookie"/> для определения доменной коллекции, которую требуется связать с <see cref="T:System.Net.Cookie"/>. /// </summary> /// <param name="cookie">Объект <see cref="T:System.Net.Cookie"/>, добавляемый в <see cref="T:System.Net.CookieContainer"/>. </param><exception cref="T:System.ArgumentNullException">Значение параметра <paramref name="cookie"/> — null. </exception><exception cref="T:System.ArgumentException">Домен для <paramref name="cookie"/> равен null или пустой строке (""). </exception><exception cref="T:System.Net.CookieException">Значение <paramref name="cookie"/> больше, чем значение <paramref name="maxCookieSize"/>–или– домен для <paramref name="cookie"/> не является допустимым URI. </exception><PermissionSet><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/></PermissionSet> public void Add(Cookie cookie) { if (cookie == null) throw new ArgumentNullException("cookie"); if (cookie.Domain.Length == 0) throw new ArgumentException(SR.GetString("net_emptystringcall"), "cookie.Domain"); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(cookie.Secure ? Uri.UriSchemeHttps : Uri.UriSchemeHttp).Append(Uri.SchemeDelimiter); if (!cookie.DomainImplicit && (int) cookie.Domain[0] == 46) stringBuilder.Append("0"); stringBuilder.Append(cookie.Domain); if (cookie.PortList != null) stringBuilder.Append(":").Append(cookie.PortList[0]); stringBuilder.Append(cookie.Path); Uri result; if (!Uri.TryCreate(((object) stringBuilder).ToString(), UriKind.Absolute, out result)) { throw new CookieException(SR.GetString("net_cookie_attribute", (object) "Domain", (object) cookie.Domain)); } else { Cookie cookie1 = cookie.Clone(); cookie1.VerifySetDefaults(cookie1.Variant, result, this.IsLocalDomain(result.Host), this.m_fqdnMyDomain, true, true); this.Add(cookie1, true); } }