C#實現簡單擷取及設定Session類

來源:互聯網
上載者:User

標籤:text   net   pos   zone   current   cursor   name   int   top   

本文執行個體講述了C#實現簡單擷取及設定Session類。分享給大家供大家參考。具體分析如下:

這是一個簡單的C#擷取Session、設定Session類檔案,本類主要實現大家最常用的兩個功能:

1、GetSession(string name)根據session名擷取session對象;

2、SetSession(string name, object val)設定session

具體代碼如下:

using System.Web;namespace DotNet.Utilities{  /// <summary>  /// Session 操作類  /// 1、GetSession(string name)根據session名擷取session對象  /// 2、SetSession(string name, object val)設定session  /// </summary>  public class SessionHelper  {    /// <summary>    /// 根據session名擷取session對象    /// </summary>    /// <param name="name"></param>    /// <returns></returns>    public static object GetSession(string name)    {      return HttpContext.Current.Session[name];    }    /// <summary>    /// 設定session    /// </summary>    /// <param name="name">session 名</param>    /// <param name="val">session 值</param>    public static void SetSession(string name, object val)    {      HttpContext.Current.Session.Remove(name);      HttpContext.Current.Session.Add(name, val);    }  }}

希望本文所述對大家的C#程式設計有所協助。

除聲明外, 跑步客文章均為原創,轉載請以連結形式標明本文地址
  C#實現簡單擷取及設定Session類

本文地址:  http://www.paobuke.com/develop/c-develop/pbk23061.html






相關內容C#使用Selenium+PhantomJS抓取資料C#如何自動識別檔案的編碼C# ping網路IP 實現網路狀態檢測的方法C#華氏溫度和攝氏溫度相互轉換的方法
C#程式提示“正由另一進程使用,因此該進程無法訪問該檔案”的解決辦法C#實現windows form限制文字框輸入的方法C#實現用於產生條碼的類理解C#中的事件

C#實現簡單擷取及設定Session類

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.