码迷,mamicode.com
首页 > Windows程序 > 详细

一个队asp.net session进行了再次封装的C#类的代码

时间:2018-12-18 12:12:13      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:return   关于   session   null   space   names   ssi   res   help   

将写内容过程经常用到的内容片段做个收藏,下边内容段是关于一个队asp.net session进行了再次封装的C#类的内容。


using System.Web;

namespace DotNet.Utilities
{
    public static class SessionHelper2
    {
        public static void Add(string strSessionName, string strValue)
        {
            HttpContext.Current.Session[strSessionName] = strValue;
            HttpContext.Current.Session.Timeout = 20;
        }

        public static void Adds(string strSessionName, string[] strValues)
        {
            HttpContext.Current.Session[strSessionName] = strValues;
            HttpContext.Current.Session.Timeout = 20;
        }

        public static void Add(string strSessionName, string strValue, int iExpires)
        {
            HttpContext.Current.Session[strSessionName] = strValue;
            HttpContext.Current.Session.Timeout = iExpires;
        }

        public static void Adds(string strSessionName, string[] strValues, int iExpires)
        {
            HttpContext.Current.Session[strSessionName] = strValues;
            HttpContext.Current.Session.Timeout = iExpires;
        }

        public static string Get(string strSessionName)
        {
            if (HttpContext.Current.Session[strSessionName] == null)
            {
                return null;
            }
            else
            {
                return HttpContext.Current.Session[strSessionName].ToString();
            }
        }

        public static string[] Gets(string strSessionName)
        {
            if (HttpContext.Current.Session[strSessionName] == null)
            {
                return null;
            }
            else
            {
                return (string[])HttpContext.Current.Session[strSessionName];
            }
        }

        public static void Del(string strSessionName)
        {
            HttpContext.Current.Session[strSessionName] = null;
        }
    }
}

一个队asp.net session进行了再次封装的C#类的代码

标签:return   关于   session   null   space   names   ssi   res   help   

原文地址:http://blog.51cto.com/14137494/2331872

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!