当前位置: 首页>>代码示例>>C#>>正文


C# Cookie.InternalSetName方法代码示例

本文整理汇总了C#中System.Net.Cookie.InternalSetName方法的典型用法代码示例。如果您正苦于以下问题:C# Cookie.InternalSetName方法的具体用法?C# Cookie.InternalSetName怎么用?C# Cookie.InternalSetName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Cookie的用法示例。


在下文中一共展示了Cookie.InternalSetName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Get

    // properties

    // methods

        //
        // 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);
                                    }
                                }
                                break;

                            case CookieToken.MaxAge:
                                if (!expiresSet) {
                                    expiresSet = true;
                                    int parsed;
                                    if (int.TryParse(CheckQuoted(m_tokenizer.Value), out parsed)) {
//.........这里部分代码省略.........
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:101,代码来源:cookie.cs

示例2: 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;
                                    cookie.Port  = string.Empty;
                                }
                                break;
                        }
                        break;
                    }
                }
            } while (!m_tokenizer.Eof && !m_tokenizer.EndOfCookie);
            return cookie;
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:95,代码来源:cookie.cs

示例3: Get

    // properties

    // methods

        //
        // 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);

                if (((token == CookieToken.NameValuePair) || (token == CookieToken.Attribute)) && (cookie == null)) {
                   cookie = new Cookie();
                   if (cookie.InternalSetName(m_tokenizer.Name) == false) {
                       cookie.InternalSetName(string.Empty);    //will be rejected
                   }
                   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;
                                    try {
                                        cookie.CommentUri = new Uri(CheckQuoted(m_tokenizer.Value));
                                    }
                                    catch {
                                            //ignore this kind of problem
                                    }
                                }
                                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;
                                    // ParseCookieDate() does many formats for the date.
                                    // Also note that the parser will eat day of the week 
                                    // plus comma and leading spaces
                                    DateTime expires;
                                    if (HttpDateParse.ParseCookieDate(CheckQuoted(m_tokenizer.Value), out expires)) {
                                        cookie.Expires = expires;
                                    }
                                    else {
                                        cookie.InternalSetName(string.Empty); //this cookie will be rejected
                                    }
                                }
                                break;

                            case CookieToken.MaxAge:
                                if (!expiresSet) {
                                    expiresSet = true;
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:cookie.cs


注:本文中的System.Net.Cookie.InternalSetName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。