asp.net 类库中获取session c#类中获取session
1. 先引入命名空间
using System.Web; using System.Web.SessionState;
在使用HttpContext.Current.Session获取session
HttpContext.Current.Session
2. Common.cs文件
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data; using System.Web.SessionState; namespace government_web.common { /// <summary> /// 常用类 /// </summary> public class Common { //是否有权限 public bool have_permission(string name) { bool op = true ; DataTable table = (DataTable)HttpContext.Current.Session["permission"]; if (table.Rows.Count > 0) { } else { //没有权限 op = false; } return op; } } }