本文整理汇总了C#中Cookie.InternalSetName方法的典型用法代码示例。如果您正苦于以下问题:C# Cookie.InternalSetName方法的具体用法?C# Cookie.InternalSetName怎么用?C# Cookie.InternalSetName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cookie
的用法示例。
在下文中一共展示了Cookie.InternalSetName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetServer
// twin parsing method, different enough that it's better to split it into
// a different method
internal Cookie GetServer()
{
Cookie cookie = m_savedCookie;
m_savedCookie = null;
// only first ocurence of an attribute value must be counted
bool domainSet = false;
bool pathSet = false;
bool portSet = false; //special case as it may have no value in header
do
{
bool first = cookie == null || cookie.Name == null || cookie.Name.Length == 0;
CookieToken token = m_tokenizer.Next(first, false);
if (first && (token == CookieToken.NameValuePair || token == CookieToken.Attribute))
{
if (cookie == null)
{
cookie = new Cookie();
}
if (cookie.InternalSetName(m_tokenizer.Name) == false)
{
//will be rejected
cookie.InternalSetName(string.Empty);
}
cookie.Value = m_tokenizer.Value;
}
else
{
switch (token)
{
case CookieToken.NameValuePair:
switch (m_tokenizer.Token)
{
case CookieToken.Domain:
if (!domainSet)
{
domainSet = true;
cookie.Domain = CheckQuoted(m_tokenizer.Value);
cookie.IsQuotedDomain = m_tokenizer.Quoted;
}
break;
case CookieToken.Path:
if (!pathSet)
{
pathSet = true;
cookie.Path = m_tokenizer.Value;
}
break;
case CookieToken.Port:
if (!portSet)
{
portSet = true;
try
{
cookie.Port = m_tokenizer.Value;
}
catch (CookieException)
{
//this cookie will be rejected
cookie.InternalSetName(string.Empty);
}
}
break;
case CookieToken.Version:
// this is a new cookie, this token is for the next cookie.
m_savedCookie = new Cookie();
int parsed;
if (int.TryParse(m_tokenizer.Value, out parsed))
{
m_savedCookie.Version = parsed;
}
return cookie;
case CookieToken.Unknown:
// this is a new cookie, the token is for the next cookie.
m_savedCookie = new Cookie();
if (m_savedCookie.InternalSetName(m_tokenizer.Name) == false)
{
//will be rejected
m_savedCookie.InternalSetName(string.Empty);
}
m_savedCookie.Value = m_tokenizer.Value;
return cookie;
}
break;
case CookieToken.Attribute:
switch (m_tokenizer.Token)
{
case CookieToken.Port:
if (!portSet)
{
portSet = true;
//.........这里部分代码省略.........
示例2: Get
//
// Get
//
// Gets the next cookie
//
// Inputs:
// Nothing
//
// Outputs:
// Nothing
//
// Assumes:
// Nothing
//
// Returns:
// new cookie object, or null if there's no more
//
// Throws:
// Nothing
//
internal Cookie Get()
{
Cookie cookie = null;
// only first ocurence of an attribute value must be counted
bool commentSet = false;
bool commentUriSet = false;
bool domainSet = false;
bool expiresSet = false;
bool pathSet = false;
bool portSet = false; //special case as it may have no value in header
bool versionSet = false;
bool secureSet = false;
bool discardSet = false;
do
{
CookieToken token = m_tokenizer.Next(cookie == null, true);
if (cookie == null && (token == CookieToken.NameValuePair || token == CookieToken.Attribute))
{
cookie = new Cookie();
if (cookie.InternalSetName(m_tokenizer.Name) == false)
{
//will be rejected
cookie.InternalSetName(string.Empty);
}
cookie.Value = m_tokenizer.Value;
}
else
{
switch (token)
{
case CookieToken.NameValuePair:
switch (m_tokenizer.Token)
{
case CookieToken.Comment:
if (!commentSet)
{
commentSet = true;
cookie.Comment = m_tokenizer.Value;
}
break;
case CookieToken.CommentUrl:
if (!commentUriSet)
{
commentUriSet = true;
Uri parsed;
if (Uri.TryCreate(CheckQuoted(m_tokenizer.Value), UriKind.Absolute, out parsed))
{
cookie.CommentUri = parsed;
}
}
break;
case CookieToken.Domain:
if (!domainSet)
{
domainSet = true;
cookie.Domain = CheckQuoted(m_tokenizer.Value);
cookie.IsQuotedDomain = m_tokenizer.Quoted;
}
break;
case CookieToken.Expires:
if (!expiresSet)
{
expiresSet = true;
DateTime expires;
if (DateTime.TryParse(CheckQuoted(m_tokenizer.Value),
CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces, out expires))
{
cookie.Expires = expires;
}
else
{
//this cookie will be rejected
cookie.InternalSetName(string.Empty);
//.........这里部分代码省略.........