欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#操作session的類實(shí)例

 更新時(shí)間:2015年03月26日 11:01:12   作者:feige  
這篇文章主要介紹了C#操作session的類,實(shí)例分析了C#針對session的添加、讀取及刪除等技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了C#操作session的類。分享給大家供大家參考。具體分析如下:

這個(gè)C#類對session操作進(jìn)行了再次封裝,可以大大簡化session的常用操作,同時(shí)這個(gè)類可以將session值設(shè)置為數(shù)組,也可以將值讀取為數(shù)組列表,如果你有這方面的需要可以使用這個(gè)類,擴(kuò)這自己對這個(gè)C#類進(jìn)行擴(kuò)展。

using System.Web;
namespace DotNet.Utilities
{
 public static class SessionHelper2
 {
  /// <summary>
  /// 添加Session,調(diào)動有效期為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,調(diào)動有效期為20分鐘
  /// </summary>
  /// <param name="strSessionName">Session對象名稱</param>
  /// <param name="strValues">Session值數(shù)組</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">調(diào)動有效期(分鐘)</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值數(shù)組</param>
  /// <param name="iExpires">調(diào)動有效期(分鐘)</param>
  public static void Adds(string strSessionName, string[] strValues, int iExpires)
  {
   HttpContext.Current.Session[strSessionName] = strValues;
   HttpContext.Current.Session.Timeout = iExpires;
  }
  /// <summary>
  /// 讀取某個(gè)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>
  /// 讀取某個(gè)Session對象值數(shù)組
  /// </summary>
  /// <param name="strSessionName">Session對象名稱</param>
  /// <returns>Session對象值數(shù)組</returns>
  public static string[] Gets(string strSessionName)
  {
   if (HttpContext.Current.Session[strSessionName] == null)
   {
    return null;
   }
   else
   {
    return (string[])HttpContext.Current.Session[strSessionName];
   }
  }
  /// <summary>
  /// 刪除某個(gè)Session對象
  /// </summary>
  /// <param name="strSessionName">Session對象名稱</param>
  public static void Del(string strSessionName)
  {
   HttpContext.Current.Session[strSessionName] = null;
  }
 }
}

希望本文所述對大家的C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評論