Session帮助类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web; namespace Test
{
/// <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,调动有效期为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 = ;
} /// <summary>
/// 添加Session,调动有效期为20分钟
/// </summary>
/// <param name="strSessionName">Session对象名称</param>
/// <param name="strValues">Session值数组</param>
public static void Adds(string strSessionName, string[] strValues)
{
HttpContext.Current.Session[strSessionName] = strValues;
HttpContext.Current.Session.Timeout = ;
} /// <summary>
/// 添加Session
/// </summary>
/// <param name="strSessionName">Session对象名称</param>
/// <param name="strValue">Session值</param>
/// <param name="iExpires">调动有效期(分钟)</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值数组</param>
/// <param name="iExpires">调动有效期(分钟)</param>
public static void Adds(string strSessionName, string[] strValues, int iExpires)
{
HttpContext.Current.Session[strSessionName] = strValues;
HttpContext.Current.Session.Timeout = iExpires;
} /// <summary>
/// 读取某个Session对象值
/// </summary>
/// <param name="strSessionName">Session对象名称</param>
/// <returns>Session对象值</returns>
public static object Get(string strSessionName)
{
if (HttpContext.Current.Session[strSessionName] == null)
{
return null;
}
else
{
return HttpContext.Current.Session[strSessionName];
}
} /// <summary>
/// 读取某个Session对象值数组
/// </summary>
/// <param name="strSessionName">Session对象名称</param>
/// <returns>Session对象值数组</returns>
public static string[] Gets(string strSessionName)
{
if (HttpContext.Current.Session[strSessionName] == null)
{
return null;
}
else
{
return (string[])HttpContext.Current.Session[strSessionName];
}
} /// <summary>
/// 删除某个Session对象
/// </summary>
/// <param name="strSessionName">Session对象名称</param>
public static void Del(string strSessionName)
{
HttpContext.Current.Session[strSessionName] = null;
}
} }
Session帮助类的更多相关文章
- C#语法糖之 session操作类 asp.net
用法: //声名一个数据集合 var listString = new List<string>() { "a", "b", "c&quo ...
- asp.net 类库中获取session c#类中获取session
asp.net 类库中获取session c#类中获取session 1. 先引入命名空间 using System.Web; using System.Web.SessionState; 在使用H ...
- session操作类
using System;using System.Web; /// <summary> ///session操作类 /// </summary> public class a ...
- C#操作session的类实例
本文实例讲述了C#操作session的类.分享给大家供大家参考.具体分析如下: 这个C#类对session操作进行了再次封装,可以大大简化session的常用操作,同时这个类可以将session值设置 ...
- C# Session 操作类
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- Js 的常用方法:页面跳转,Session,类继承
MyApp.Base = function () { } var basePrototype = MyApp.Base["prototype"]; //对象克隆方法 basePro ...
- Apache MINA 框架之默认session管理类实现
DefaultSocketSessionConfig 类 extends AbstractSocketSessionConfig extends AbstractIoSessionConfig imp ...
- C#操作session的类实例(转)
using System.Web; namespace DotNet.Utilities { public static class SessionHelper2 { /// <summary& ...
- 数据表中记录明明有,session.get(类.class, id);返回null
出现null的处理思路首先检查数据库中是否真的有这个记录 确实存在的,用接口查一下最大值,也是存在的,数据库连接正常 写sql也可以查得到 然而诡异的事情出现了 难道是一直在用的dao代码出了问题? ...
随机推荐
- Linux 磁盘使用查看 查看使用磁盘程序 Monitoring disk activity in linux
5 TOOLS FOR MONITORING DISK ACTIVITY IN LINUX Here is a quick overview of 5 command-line tools that ...
- Django 使用模型的API
进入项目目录 python3运行 import os os.environ['DJANGO_SETTINGS_MODULE']= '项目.settings' import django django. ...
- 带你熟悉SQLServer2016中的System-Versioned Temporal Table 版本由系统控制的临时表
什么是 System-Versioned Temporal Table? System-Versioned Temporal Table,暂且容我管它叫版本由系统控制的临时表,它是 SQL Serve ...
- REPLACE函数的使用方法
Replace函数的含义~ 用新字符串替换旧字符串,而且替换的位置和数量都是指定的. replace函数的语法格式 =Replace(old_text,start_num,num_chars,new_ ...
- IP负载均衡
推荐一篇关于LVS的好文: https://www.cnblogs.com/gaoxu387/p/7941381.html 一.原博主要内容: 1.概述 IP负载均衡:四层负载,是基于IP+端口的负载 ...
- webApi core2 DI通过代码来获取容器里面已注入的对象
请求服务 来自 HttpContext 的一次 ASP.NET 请求中可用的服务通过 RequestServices 集合公开的. 请求服务将你配置的服务和请求描述为应用程序的一部分.当你的对象指定依 ...
- systemd 和 如何修改和创建一个 systemd service (Understanding and administering systemd)
系统中经常会使用到 systemctl 去管理systemd程序,刚刚看了一篇关于 systemd 和 SysV 相关的文章,这里简要记录一下: systemd定义: (英文来解释更为原汁原味) sy ...
- WPF防止重复运行实例
1.方法一 在app.xaml.cs下添加如下代码: /// <summary> /// App.xaml 的交互逻辑 /// </summary> public partia ...
- python第五十课——多态性
animal.py class Animal: def __init__(self,name): self.name = name def eat(self): pass dog.py from an ...
- ASP.NET中HttpApplication中ProcessRequest方法中运行的事件顺序;ASP.NET WebForm和MVC总体请求流程图
ASP.NET中HttpApplication中ProcessRequest方法中运行的事件顺序 1.BeginRequest 開始处理请求 2.AuthenticateRequest 授权验证请求 ...