zoukankan      html  css  js  c++  java
  • C#操作session的类实例(转)

    using System.Web;
    namespace DotNet.Utilities
    {
     public static class SessionHelper2
     {
      /// <summary>
      /// 添加Session,调动有效期为20分钟
      /// </summary>
      /// <param name="strSessionName">Session对象名称</param>
      /// <param name="strValue">Session值</param>
      public static void Add(string strSessionName, string strValue)
      {
       HttpContext.Current.Session[strSessionName] = strValue;
       HttpContext.Current.Session.Timeout = 20;
      }
      /// <summary>
      /// 添加Session,调动有效期为20分钟
      /// </summary>
      /// <param name="strSessionName">Session对象名称</param>
      /// <param name="strValues">Session值数组</param>
      public static void Adds(string strSessionName, string[] strValues)
      {
       HttpContext.Current.Session[strSessionName] = strValues;
       HttpContext.Current.Session.Timeout = 20;
      }
      /// <summary>
      /// 添加Session
      /// </summary>
      /// <param name="strSessionName">Session对象名称</param>
      /// <param name="strValue">Session值</param>
      /// <param name="iExpires">调动有效期(分钟)</param>
      public static void Add(string strSessionName, string strValue, int iExpires)
      {
       HttpContext.Current.Session[strSessionName] = strValue;
       HttpContext.Current.Session.Timeout = iExpires;
      }
      /// <summary>
      /// 添加Session
      /// </summary>
      /// <param name="strSessionName">Session对象名称</param>
      /// <param name="strValues">Session值数组</param>
      /// <param name="iExpires">调动有效期(分钟)</param>
      public static void Adds(string strSessionName, string[] strValues, int iExpires)
      {
       HttpContext.Current.Session[strSessionName] = strValues;
       HttpContext.Current.Session.Timeout = iExpires;
      }
      /// <summary>
      /// 读取某个Session对象值
      /// </summary>
      /// <param name="strSessionName">Session对象名称</param>
      /// <returns>Session对象值</returns>
      public static string Get(string strSessionName)
      {
       if (HttpContext.Current.Session[strSessionName] == null)
       {
        return null;
       }
       else
       {
        return HttpContext.Current.Session[strSessionName].ToString();
       }
      }
      /// <summary>
      /// 读取某个Session对象值数组
      /// </summary>
      /// <param name="strSessionName">Session对象名称</param>
      /// <returns>Session对象值数组</returns>
      public static string[] Gets(string strSessionName)
      {
       if (HttpContext.Current.Session[strSessionName] == null)
       {
        return null;
       }
       else
       {
        return (string[])HttpContext.Current.Session[strSessionName];
       }
      }
      /// <summary>
      /// 删除某个Session对象
      /// </summary>
      /// <param name="strSessionName">Session对象名称</param>
      public static void Del(string strSessionName)
      {
       HttpContext.Current.Session[strSessionName] = null;
      }
     }
    }
    
  • 相关阅读:
    SkyWorking基础:6.2版本安装部署
    ZooKeeper基础:快速部署
    Linux基础:uniq命令总结
    Linux基础:seq命令总结
    JavaScript BOM对象
    JavaScript常用项目(更新至19.11.17)
    JavaScript触发器
    JavaScript选择器和节点操作
    小花梨的取石子游戏【博弈】
    杨辉三角打表
  • 原文地址:https://www.cnblogs.com/xiaobaizitaibai/p/8656236.html
Copyright © 2011-2022 走看看