一個隊asp.net session進行了再次封裝的C#類的代碼
阿新 • • 發佈:2018-12-18
out time oid 再次 current web mes get pub 將寫內容過程經常用到的內容片段做個收藏,下邊內容段是關於一個隊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#類的代碼