如何做一个静态类的静态方法专门提取Session中用户名的值,
使每个页面一调这个静态的方法便可以取到?

解决方案 »

  1.   

      public static string userData
     {
    get{return Sesson[""].toString();}
    }
      

  2.   

    public string GetUserName(string key)
    {
        return (string)Session【key】;
    }
      

  3.   

        public class SessionManage
        {
            public static string GetSession(string name)
            {
                HttpContext context = HttpContext.Current;
                if (context == null || context.Session[name] == null)
                {
                    return string.Empty;
                }
                else
                {
                    return context.Session[name].ToString();
                }
            }
        }