FormsAuthenticationTicket.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / Security / FormsAuthenticationTicket.cs / 1305376 / FormsAuthenticationTicket.cs

                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

/* 
 * FormsAuthenticationTicket class 
 *
 * Copyright (c) 1999 Microsoft Corporation 
 */

namespace System.Web.Security {
    using System.Security.Principal; 
    using System.Security.Permissions;
    using System.Web.Configuration; 
    using System.Runtime.Serialization; 

 
    /// 
    ///    This class encapsulates the information represented in
    ///       an authentication cookie as used by FormsAuthenticationModule.
    ///  
    [Serializable]
    public sealed class FormsAuthenticationTicket { 
 
        /// 
        ///    A one byte version number for future 
        ///       use.
        /// 
        public int       Version { get { return _Version;}}
 
        /// 
        ///    The user name associated with the 
        ///    authentication cookie. Note that, at most, 32 bytes are stored in the 
        ///    cookie.
        ///  
        public String    Name { get { return _Name;}}

        /// 
        ///    The date/time at which the cookie 
        ///    expires.
        ///  
        public DateTime  Expiration { get { return _Expiration;}} 

        ///  
        ///    The time at which the cookie was originally
        ///    issued. This can be used for custom expiration schemes.
        /// 
        public DateTime  IssueDate { get { return _IssueDate;}} 

        ///  
        ///    True if a durable cookie was issued. 
        ///    Otherwise, the authentication cookie is scoped to the browser lifetime.
        ///  
        public bool      IsPersistent { get { return _IsPersistent;}}

        /// 
        ///    [To be supplied.] 
        /// 
        public bool Expired { get { return Expiration < DateTime.Now;}} 
 
        /// 
        ///    [To be supplied.] 
        /// 
        public String    UserData { get { return _UserData;}}

 
        /// 
        ///    [To be supplied.] 
        ///  
        public String    CookiePath { get { return _CookiePath;}}
 
        internal int InternalVersion {
            get {
                return _InternalVersion;
            } 
            set {
                _InternalVersion = value; 
            } 
        }
 
        internal Byte[] InternalData {
            get {
                return _InternalData;
            } 
            set {
                _InternalData = value; 
            } 
        }
 

        private int       _Version;
        private String    _Name;
        private DateTime  _Expiration; 
        private DateTime  _IssueDate;
        private bool      _IsPersistent; 
        private String    _UserData; 
        private String    _CookiePath;
        [OptionalField(VersionAdded = 2)] 
        private int _InternalVersion;
        [OptionalField(VersionAdded = 2)]
        private Byte[] _InternalData;
 

        ///  
        ///    This constructor creates a 
        ///       FormsAuthenticationTicket instance with explicit values.
        ///  
        public FormsAuthenticationTicket(int version,
                                          String name,
                                          DateTime issueDate,
                                          DateTime expiration, 
                                          bool isPersistent,
                                          String userData) { 
            _Version = version; 
            _Name = name;
            _Expiration = expiration; 
            _IssueDate = issueDate;
            _IsPersistent = isPersistent;
            _UserData = userData;
            _CookiePath = FormsAuthentication.FormsCookiePath; 
        }
 
 
        public FormsAuthenticationTicket(int version,
                                          String name, 
                                          DateTime issueDate,
                                          DateTime expiration,
                                          bool isPersistent,
                                          String userData, 
                                          String cookiePath) {
            _Version = version; 
            _Name = name; 
            _Expiration = expiration;
            _IssueDate = issueDate; 
            _IsPersistent = isPersistent;
            _UserData = userData;
            _CookiePath = cookiePath;
        } 

 
 
        /// 
        ///     This constructor creates 
        ///       a FormsAuthenticationTicket instance with the specified name and cookie durability,
        ///       and default values for the other settings.
        /// 
        public FormsAuthenticationTicket(String name, bool isPersistent, Int32 timeout) { 
            _Version = 2;
            _Name = name; 
            _IssueDate = DateTime.Now; 
            _IsPersistent = isPersistent;
            _UserData = ""; 
            _Expiration = DateTime.Now.AddMinutes(timeout);
            _CookiePath = FormsAuthentication.FormsCookiePath;
        }
    } 
}
 
 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

/* 
 * FormsAuthenticationTicket class 
 *
 * Copyright (c) 1999 Microsoft Corporation 
 */

namespace System.Web.Security {
    using System.Security.Principal; 
    using System.Security.Permissions;
    using System.Web.Configuration; 
    using System.Runtime.Serialization; 

 
    /// 
    ///    This class encapsulates the information represented in
    ///       an authentication cookie as used by FormsAuthenticationModule.
    ///  
    [Serializable]
    public sealed class FormsAuthenticationTicket { 
 
        /// 
        ///    A one byte version number for future 
        ///       use.
        /// 
        public int       Version { get { return _Version;}}
 
        /// 
        ///    The user name associated with the 
        ///    authentication cookie. Note that, at most, 32 bytes are stored in the 
        ///    cookie.
        ///  
        public String    Name { get { return _Name;}}

        /// 
        ///    The date/time at which the cookie 
        ///    expires.
        ///  
        public DateTime  Expiration { get { return _Expiration;}} 

        ///  
        ///    The time at which the cookie was originally
        ///    issued. This can be used for custom expiration schemes.
        /// 
        public DateTime  IssueDate { get { return _IssueDate;}} 

        ///  
        ///    True if a durable cookie was issued. 
        ///    Otherwise, the authentication cookie is scoped to the browser lifetime.
        ///  
        public bool      IsPersistent { get { return _IsPersistent;}}

        /// 
        ///    [To be supplied.] 
        /// 
        public bool Expired { get { return Expiration < DateTime.Now;}} 
 
        /// 
        ///    [To be supplied.] 
        /// 
        public String    UserData { get { return _UserData;}}

 
        /// 
        ///    [To be supplied.] 
        ///  
        public String    CookiePath { get { return _CookiePath;}}
 
        internal int InternalVersion {
            get {
                return _InternalVersion;
            } 
            set {
                _InternalVersion = value; 
            } 
        }
 
        internal Byte[] InternalData {
            get {
                return _InternalData;
            } 
            set {
                _InternalData = value; 
            } 
        }
 

        private int       _Version;
        private String    _Name;
        private DateTime  _Expiration; 
        private DateTime  _IssueDate;
        private bool      _IsPersistent; 
        private String    _UserData; 
        private String    _CookiePath;
        [OptionalField(VersionAdded = 2)] 
        private int _InternalVersion;
        [OptionalField(VersionAdded = 2)]
        private Byte[] _InternalData;
 

        ///  
        ///    This constructor creates a 
        ///       FormsAuthenticationTicket instance with explicit values.
        ///  
        public FormsAuthenticationTicket(int version,
                                          String name,
                                          DateTime issueDate,
                                          DateTime expiration, 
                                          bool isPersistent,
                                          String userData) { 
            _Version = version; 
            _Name = name;
            _Expiration = expiration; 
            _IssueDate = issueDate;
            _IsPersistent = isPersistent;
            _UserData = userData;
            _CookiePath = FormsAuthentication.FormsCookiePath; 
        }
 
 
        public FormsAuthenticationTicket(int version,
                                          String name, 
                                          DateTime issueDate,
                                          DateTime expiration,
                                          bool isPersistent,
                                          String userData, 
                                          String cookiePath) {
            _Version = version; 
            _Name = name; 
            _Expiration = expiration;
            _IssueDate = issueDate; 
            _IsPersistent = isPersistent;
            _UserData = userData;
            _CookiePath = cookiePath;
        } 

 
 
        /// 
        ///     This constructor creates 
        ///       a FormsAuthenticationTicket instance with the specified name and cookie durability,
        ///       and default values for the other settings.
        /// 
        public FormsAuthenticationTicket(String name, bool isPersistent, Int32 timeout) { 
            _Version = 2;
            _Name = name; 
            _IssueDate = DateTime.Now; 
            _IsPersistent = isPersistent;
            _UserData = ""; 
            _Expiration = DateTime.Now.AddMinutes(timeout);
            _CookiePath = FormsAuthentication.FormsCookiePath;
        }
    } 
}
 
 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.

                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK