上一篇介绍的是Cookie常用的方法,这次介绍Web的另外一个传值,Session常用的方法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
public static class Session { /// <summary> /// 写入Session /// </summary> /// <param name="name"></param> /// <param name="value"></param> public static void WriteSession(string name, object value) { System.Web.HttpContext.Current.Session[name] = value; } public static string ReadSession(string name) { if (System.Web.HttpContext.Current.Session[name] != null) { return System.Web.HttpContext.Current.Session[name].ToString(); } else { return ""; } } public static void ClearSession(string name) { System.Web.HttpContext.Current.Session[name] = ""; } } |