2013-02-28 86 views
1

这是我得到的错误 “会话状态在此上下文中不可用”。在Global.asax中检索会话

只是一个业余程序员,我怎么能在Global.asax中

检索会议,这是我在Global.asax中

public class Global : System.Web.HttpApplication 
{ 
    protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e) 
    { 
     if (FormsAuthentication.CookiesSupported == true) 
     { 
      if (Request.Cookies[FormsAuthentication.FormsCookieName] != null) 
      { 
       try 
       {    
        string Email = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name; 
        string Roles = LoginVerification.GetUserRoles(Email); 
        string DisplayName = (string)Session["DisplayName"]; 
        e.User = new System.Security.Principal.GenericPrincipal(
        new System.Security.Principal.GenericIdentity(DisplayName, "Forms"), Roles.Split(';')); 
       } 
       catch (Exception) 
       { 

       } 
      } 
     } 
    } 

    protected void Application_Start(object sender, EventArgs e) 
    { 

    } 

    protected void Session_Start(object sender, EventArgs e) 
    { 

    } 

    protected void Application_BeginRequest(object sender, EventArgs e) 
    { 

    } 

    protected void Application_AuthenticateRequest(object sender, EventArgs e) 
    { 

    } 

    protected void Application_Error(object sender, EventArgs e) 
    { 

    } 

    protected void Session_End(object sender, EventArgs e) 
    { 

    } 

    protected void Application_End(object sender, EventArgs e) 
    { 

    } 
} 

代码预先感谢您回答我的问题! :)

+1

没有尝试HttpContext.Current.Session – happygilmore 2013-02-28 11:31:16

+0

也许一个检查,看是否会话[“显示名称”]为空第一 – 2013-02-28 11:35:13

回答