zoukankan      html  css  js  c++  java
  • [Session] SessionHelper2---C#关于Session高级操作帮助类 (转载)

    点击下载 SessionHelper2.rar

    这个类是关于Session的一些高级操作
    1.添加时限制时间
    2.读取对象
    3.读取数据等等
    看下面代码吧

    /// <summary>
    /// 联系方式:361983679  
    /// 更新网站:[url=http://www.cckan.net/thread-655-1-1.html]http://www.cckan.net/thread-655-1-1.html[/url]
    /// </summary>
    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;
            }
        }
    }
  • 相关阅读:
    YOLOV2相对于YOLOV1的改进
    在训练过程中loss出现NaN的原因以及可以采取的方法
    出现梯度消失和梯度爆炸的原因及解决方案
    Batch Normalization 原理
    几种激活函数的对比(二)
    几种激活函数对比(一)
    Leetcode 830. Positions of Large Groups
    Leetcode 985. Sum of Even Numbers After Queries
    python中的赋值与拷贝(浅拷贝与深拷贝)
    Leetcode 665. Non-decreasing Array
  • 原文地址:https://www.cnblogs.com/lizeyan/p/3628405.html
Copyright © 2011-2022 走看看