/// <summary> /// 获取Session /// </summary> /// <param name="strName"></param> /// <returns></returns> public static object GetSession(string strName) { byte[] result; try { MyHttpContext.Current.Session.TryGetValue(strName, out result); if (result == null || result.Length <= 0) { return(""); } object strResult = ByteConvertHelper.Bytes2Object <object>(result); if (strResult == null) { return(""); } return(strResult); } catch (Exception ex) { // XTrace.WriteLine($"获取Session出错:{ex.Message}"); return(""); } }
/// <summary> /// 设置Session /// </summary> /// <param name="strName">名称</param> /// <param name="value">值</param> public static void WriteSession(string strName, object value) { MyHttpContext.Current.Session.Set(strName, ByteConvertHelper.Object2Bytes(value)); }