您的位置:首页 > 编程语言 > ASP

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

2018-12-18 10:14 78 查看

将写内容过程经常用到的内容片段做个收藏,下边内容段是关于一个队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;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  封装 代码
相关文章推荐