FormsAuthenticationTicket.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //
  2. // System.Web.Security.FormsAuthenticationTicket
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. //
  7. // (C) 2002 Ximian, Inc (http://www.ximian.com)
  8. //
  9. using System;
  10. namespace System.Web.Security
  11. {
  12. [Serializable]
  13. public sealed class FormsAuthenticationTicket
  14. {
  15. int version;
  16. string name;
  17. DateTime issueDate;
  18. DateTime expiration;
  19. bool isPersistent;
  20. string userData;
  21. string cookiePath;
  22. public FormsAuthenticationTicket (int version,
  23. string name,
  24. DateTime issueDate,
  25. DateTime expiration,
  26. bool isPersistent,
  27. string userData)
  28. {
  29. this.version = version;
  30. this.name = name;
  31. this.issueDate = issueDate;
  32. this.expiration = expiration;
  33. this.isPersistent = isPersistent;
  34. this.userData = userData;
  35. this.cookiePath = "/";
  36. }
  37. public FormsAuthenticationTicket (int version,
  38. string name,
  39. DateTime issueDate,
  40. DateTime expiration,
  41. bool isPersistent,
  42. string userData,
  43. string cookiePath)
  44. {
  45. this.version = version;
  46. this.name = name;
  47. this.issueDate = issueDate;
  48. this.expiration = expiration;
  49. this.isPersistent = isPersistent;
  50. this.userData = userData;
  51. this.cookiePath = cookiePath;
  52. }
  53. public FormsAuthenticationTicket (string name, bool isPersistent, int timeout)
  54. {
  55. this.version = 1;
  56. this.name = name;
  57. this.issueDate = DateTime.Now;
  58. this.isPersistent = isPersistent;
  59. if (isPersistent)
  60. expiration = issueDate.AddYears (50);
  61. else
  62. expiration = issueDate.AddMinutes ((double) timeout);
  63. this.userData = String.Empty;
  64. this.cookiePath = "/";
  65. }
  66. internal void SetDates (DateTime issueDate, DateTime expiration)
  67. {
  68. this.issueDate = issueDate;
  69. this.expiration = expiration;
  70. }
  71. internal FormsAuthenticationTicket Clone ()
  72. {
  73. return new FormsAuthenticationTicket (version,
  74. name,
  75. issueDate,
  76. expiration,
  77. isPersistent,
  78. userData,
  79. cookiePath);
  80. }
  81. public string CookiePath
  82. {
  83. get {
  84. return cookiePath;
  85. }
  86. }
  87. public DateTime Expiration
  88. {
  89. get {
  90. return expiration;
  91. }
  92. }
  93. public bool Expired
  94. {
  95. get {
  96. return DateTime.Now > expiration;
  97. }
  98. }
  99. public bool IsPersistent
  100. {
  101. get {
  102. return isPersistent;
  103. }
  104. }
  105. public DateTime IssueDate
  106. {
  107. get {
  108. return issueDate;
  109. }
  110. }
  111. public string Name
  112. {
  113. get {
  114. return name;
  115. }
  116. }
  117. public string UserData
  118. {
  119. get {
  120. return userData;
  121. }
  122. }
  123. public int Version
  124. {
  125. get {
  126. return version;
  127. }
  128. }
  129. }
  130. }