在用户登录时, 保存了 session["UserName"]
请问:在global.asax 如何取到 session["UserName"]?

解决方案 »

  1.   

    void Application_AcquireRequestState(object sender, EventArgs e)
        {
            string str = HttpContext.Current.Session.SessionID;
        }    void Application_PreRequestHandlerExecute(object sender, EventArgs e)
        {
            string str = HttpContext.Current.Session.SessionID;
        }
      

  2.   

    谢谢一楼!
    以下代码为什么不执行?void Application_AcquireRequestState(object sender, EventArgs e)
            {
                HttpApplication App = (HttpApplication)sender;
                HttpContext Ctx = App.Context;            if (Ctx.Request.IsAuthenticated == true)
                {
                    FormsIdentity Id = (FormsIdentity)Ctx.Session["UserName"];
                    string TempRoles = Ctx.Session["Roles"].ToString();
                    string[] Roles = TempRoles.Split(',');
                    Ctx.User = new GenericPrincipal(Id, Roles);
                }
            }
      

  3.   

    string message = session["UserName"];
         注意类型转换
      

  4.   

    string message = session["UserName"];