FormsAuthenticationTicket.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. namespace System.Web.Security
  31. {
  32. [Serializable]
  33. public sealed class FormsAuthenticationTicket
  34. {
  35. int version;
  36. string name;
  37. DateTime issueDate;
  38. DateTime expiration;
  39. bool isPersistent;
  40. string userData;
  41. string cookiePath;
  42. public FormsAuthenticationTicket (int version,
  43. string name,
  44. DateTime issueDate,
  45. DateTime expiration,
  46. bool isPersistent,
  47. string userData)
  48. {
  49. this.version = version;
  50. this.name = name;
  51. this.issueDate = issueDate;
  52. this.expiration = expiration;
  53. this.isPersistent = isPersistent;
  54. this.userData = userData;
  55. this.cookiePath = "/";
  56. }
  57. public FormsAuthenticationTicket (int version,
  58. string name,
  59. DateTime issueDate,
  60. DateTime expiration,
  61. bool isPersistent,
  62. string userData,
  63. string cookiePath)
  64. {
  65. this.version = version;
  66. this.name = name;
  67. this.issueDate = issueDate;
  68. this.expiration = expiration;
  69. this.isPersistent = isPersistent;
  70. this.userData = userData;
  71. this.cookiePath = cookiePath;
  72. }
  73. public FormsAuthenticationTicket (string name, bool isPersistent, int timeout)
  74. {
  75. this.version = 1;
  76. this.name = name;
  77. this.issueDate = DateTime.Now;
  78. this.isPersistent = isPersistent;
  79. if (isPersistent)
  80. expiration = issueDate.AddYears (50);
  81. else
  82. expiration = issueDate.AddMinutes ((double) timeout);
  83. this.userData = String.Empty;
  84. this.cookiePath = "/";
  85. }
  86. internal void SetDates (DateTime issueDate, DateTime expiration)
  87. {
  88. this.issueDate = issueDate;
  89. this.expiration = expiration;
  90. }
  91. internal FormsAuthenticationTicket Clone ()
  92. {
  93. return new FormsAuthenticationTicket (version,
  94. name,
  95. issueDate,
  96. expiration,
  97. isPersistent,
  98. userData,
  99. cookiePath);
  100. }
  101. public string CookiePath
  102. {
  103. get {
  104. return cookiePath;
  105. }
  106. }
  107. public DateTime Expiration
  108. {
  109. get {
  110. return expiration;
  111. }
  112. }
  113. public bool Expired
  114. {
  115. get {
  116. return DateTime.Now > expiration;
  117. }
  118. }
  119. public bool IsPersistent
  120. {
  121. get {
  122. return isPersistent;
  123. }
  124. }
  125. public DateTime IssueDate
  126. {
  127. get {
  128. return issueDate;
  129. }
  130. }
  131. public string Name
  132. {
  133. get {
  134. return name;
  135. }
  136. }
  137. public string UserData
  138. {
  139. get {
  140. return userData;
  141. }
  142. }
  143. public int Version
  144. {
  145. get {
  146. return version;
  147. }
  148. }
  149. }
  150. }