2015-01-13 81 views
6

に設定されていない私はこの問題は、毎回セッションがオブジェクトであることはnullであるということである私のGlobal.asaxASP.NET MVCセッションがnullです。セッション変数は

protected void Application_AcquireRequestState(object sender, EventArgs e) 
{   
    if (HttpContext.Current.Handler is IRequiresSessionState) 
    { 
     if (Request.IsAuthenticated) 
     { 
      if (HttpContext.Current.Session[this.MemberShipProvider.PrincipalSessionKey] != null) 
      { 
       CxPrincipal principal; 
       try 
       { 
        principal = (CxPrincipal)HttpContext.Current.Session[this.MemberShipProvider.PrincipalSessionKey]; 
       } 
       catch 
       { 
        principal = null; 
       } 

       HttpContext.Current.User = principal; 
       Thread.CurrentPrincipal = principal; 
      } 
      else 
      { 
       var identity = new CxIdentity("admin", 1, "", true); 
       CxPrincipal principalLogin = new CxPrincipal(identity, 1); 
       HttpContext.Current.Session[this.MemberShipProvider.PrincipalSessionKey] = principalLogin; 
       HttpContext.Current.Session[SessionName.CurrentUser] = "Admin User"; 
       HttpContext.Current.User = principalLogin; 
       Thread.CurrentPrincipal = principalLogin; 
       this.FormServiceProvider.SignIn("admin", false); // this is equal to FormsAuthentication.SetAuthCookie 

      } 
     } 
    } 
} 

に次のコードを持っています。ここだけでなく、自分のアプリケーションでセッションを使用することもできません。セッションがリセットされているか、そのようなものです。

マイアプリに追加してログインする必要はありません。したがって、私はアプリケーションでSession.ClearまたはSession.Abandonを使用していません。

どうすれば私のセッション変数が設定されていないのですか?あなたが実装する必要があります(とメガバイトを空のまま)

+0

[ASP.NET MVCでのセッション状態を有効にする]の可能な重複(http://stackoverflow.com/questions/ 2620520/enable-session-state-in-asp-net-mvc) – Krumelur

+0

デバッグから何が伝えられましたか? –

+0

@AntPデバッグ中にセッションオブジェクトがありますが、変数が設定されていません。 – progrAmmar

答えて

3

あなたglobal.asax.cs内の2つの方法:

void Session_Start(object sender, EventArgs e) 
    { 
    } 

    void Session_End(object sender, EventArgs e) 
    { 

    } 
+1

これを空白で実装しても役に立たなかったので、セッション関連のコードをセッション開始に転送したところ、それは魅力的なものでした:D。ありがとう – progrAmmar

関連する問題