[WebMethod(EnableSession = true)] public static string SayHello() { LxUserContext depno = HttpContext.Current.Session["UserContext"] as LxUserContext; string depnos = depno.User.Department.ID; .......
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Net; using CityMgr; using CityMgr.Base; namespace WebApp { /// <summary> /// 用户上下文 /// </summary> [Serializable] public class LxUserContext { /// <summary> /// 当前用户 /// </summary> public LxPerson User { get; set; } /// <summary> /// 当前用户拥有的权限列表 /// </summary> public List<LxAuth> HoldAuth { get; set; } /// <summary> /// 登录时间 /// </summary> public DateTime LoginTime { get; set; } /// <summary> /// 客户端IP地址 /// </summary> public string IP { get; set; } /// <summary> /// 验证权限 /// </summary> /// <param name="authId">权限ID</param> /// <returns>是否拥有此权限</returns> public bool ValidateAuth(string authId) { return HoldAuth.Contains(new LxAuth() { ID = authId }); } /// <summary> /// 验证权限 /// </summary> /// <param name="authIds">权限ID列表</param> /// <returns>是否拥有此权限</returns> public bool ValidateAuth(string[] authIds) { bool result = false; foreach (var auth in authIds) { if (HoldAuth.Contains(new LxAuth() { ID = auth })) result = true; break; } return result; } /// <summary> /// 获取当前用户登录上下文 /// </summary> /// <returns>用户登录上下文</returns> [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.Read)] public static LxUserContext GetCurUserContext() { var obj = HttpContext.Current.Session["UserContext"] as LxUserContext; obj.User.Department.LoadData(); return obj; } } }