2013-02-28 70 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

回答