Command_Session.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*******************************************************************************
  2. * iNethinkCMS - 网站内容管理系统
  3. * Copyright (C) 2012-2013 inethink.com
  4. *
  5. * @author jackyang <69991000@qq.com>
  6. * @website http://cms.inethink.com
  7. * @version 1.3.6.0 (2013-08-14)
  8. *
  9. * This is licensed under the GNU LGPL, version 3.0 or later.
  10. * For details, see: http://www.gnu.org/licenses/gpl-3.0.html
  11. *******************************************************************************/
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Text;
  15. using System.Web;
  16. namespace iNethinkCMS.Command
  17. {
  18. public class Command_Session
  19. {
  20. /// <summary>
  21. /// 添加Session,有效期为20分钟
  22. /// </summary>
  23. /// <param name="strSessionName">Session对象名称</param>
  24. /// <param name="strValue">Session值</param>
  25. public static void Add(string strSessionName, string strValue)
  26. {
  27. HttpContext.Current.Session[strSessionName] = strValue;
  28. HttpContext.Current.Session.Timeout = 20;
  29. }
  30. /// <summary>
  31. /// 添加Session,有效期为20分钟
  32. /// </summary>
  33. /// <param name="strSessionName">Session对象名称</param>
  34. /// <param name="strValues">Session值数组</param>
  35. public static void Adds(string strSessionName, string[] strValues)
  36. {
  37. HttpContext.Current.Session[strSessionName] = strValues;
  38. HttpContext.Current.Session.Timeout = 20;
  39. }
  40. /// <summary>
  41. /// 添加Session
  42. /// </summary>
  43. /// <param name="strSessionName">Session对象名称</param>
  44. /// <param name="strValue">Session值</param>
  45. /// <param name="iExpires">有效期(分钟)</param>
  46. public static void Add(string strSessionName, string strValue, int iExpires)
  47. {
  48. HttpContext.Current.Session[strSessionName] = strValue;
  49. HttpContext.Current.Session.Timeout = iExpires;
  50. }
  51. /// <summary>
  52. /// 添加Session
  53. /// </summary>
  54. /// <param name="strSessionName">Session对象名称</param>
  55. /// <param name="strValues">Session值数组</param>
  56. /// <param name="iExpires">有效期(分钟)</param>
  57. public static void Adds(string strSessionName, string[] strValues, int iExpires)
  58. {
  59. HttpContext.Current.Session[strSessionName] = strValues;
  60. HttpContext.Current.Session.Timeout = iExpires;
  61. }
  62. /// <summary>
  63. /// 读取某个Session对象值
  64. /// </summary>
  65. /// <param name="strSessionName">Session对象名称</param>
  66. /// <returns>Session对象值</returns>
  67. public static string Get(string strSessionName)
  68. {
  69. if (HttpContext.Current.Session[strSessionName] == null)
  70. {
  71. return null;
  72. }
  73. else
  74. {
  75. return HttpContext.Current.Session[strSessionName].ToString();
  76. }
  77. }
  78. /// <summary>
  79. /// 读取某个Session对象值数组
  80. /// </summary>
  81. /// <param name="strSessionName">Session对象名称</param>
  82. /// <returns>Session对象值数组</returns>
  83. public static string[] Gets(string strSessionName)
  84. {
  85. if (HttpContext.Current.Session[strSessionName] == null)
  86. {
  87. return null;
  88. }
  89. else
  90. {
  91. return (string[])HttpContext.Current.Session[strSessionName];
  92. }
  93. }
  94. /// <summary>
  95. /// 删除某个Session对象
  96. /// </summary>
  97. /// <param name="strSessionName">Session对象名称</param>
  98. public static void Del(string strSessionName)
  99. {
  100. HttpContext.Current.Session[strSessionName] = null;
  101. }
  102. }
  103. }