本文整理汇总了C#中System.Net.Cookie.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Cookie.Clone方法的具体用法?C# Cookie.Clone怎么用?C# Cookie.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Cookie
的用法示例。
在下文中一共展示了Cookie.Clone方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Add
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);
}
示例2: SetCookie
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");
}
}
示例3: Add
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);
}
示例4: Add
/// <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);
}
}