• C# Session 操作类


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Web;
    
    namespace Dw.Util
    {
        /// <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);
            }
    
            /// <summary>
            /// 清空所有的Session
            /// </summary>
            /// <returns></returns>
            public static void ClearSession()
            {
                HttpContext.Current.Session.Clear();
            }
    
            /// <summary>
            /// 删除一个指定的ession
            /// </summary>
            /// <param name="name">Session名称</param>
            /// <returns></returns>
            public static void RemoveSession(string name)
            {
                HttpContext.Current.Session.Remove(name);
            }
    
            /// <summary>
            /// 删除所有的ession
            /// </summary>
            /// <returns></returns>
            public static void RemoveAllSession(string name)
            {
                HttpContext.Current.Session.RemoveAll();
            }
        }
    }
  • 相关阅读:
    ios 属性的特性
    ios 线程锁 与 线程交互
    iOS 变量名前为什么要加_下划线
    ios 常见问题
    ios 沙盒
    ios 去掉屏幕键盘的方法
    UITableView方法详解
    Image View、Text Field、Keyboard 隐藏键盘
    用php 进行对文件的操作 (上)
    文件上传-------头像上传预览
  • 原文地址:https://www.cnblogs.com/yechangzhong-826217795/p/11865922.html
Copyright © 2020-2023  润新知