2017-01-20 7 views
1

型「System.NullReferenceException」の例外が、これは誤りである私はC#と.Netプラットフォームで1つのWebページを編集しています。私は私がクリックしたとき、それは誤り

Additional information: Object reference not set to an instance of an object.App_Code.p9yip9ku.dllで発生したが、ユーザーコードで処理されなかった私を示すことログアウトボタンがあります。

using System.Configuration; 
using UserActionLogger; 

/// <summary> 
/// Summary description for UserActions 
/// </summary> 
public static class UserData 
{ 
    private static UserActions _uaUserActions; 

    public static void InitUserData(int uID, string IP) 
    { 
     var cString = ConfigurationManager.ConnectionStrings["basteConnectionString"].ConnectionString; 
     _uaUserActions = new UserActions(cString, uID, IP); 
    } 

    public static void Logout() 
    { 
     _uaUserActions.Logout(); 
    } 

    public static void InsertAction(int actionid, long value) 
    { 
     _uaUserActions.InsertAction(actionid, value); 
    } 

} 

および機能は同じように呼び出され:

私のコードがあるウルUserData

else if (type == 1002) //User Logout 
      { 
       Session["current_user"] = "NoUser"; 

       UserData.Logout(); 
       var jss = new JavaScriptSerializer(); 
       this.Response.Write(jss.Serialize(Session["current_user"])); 
       this.Response.ContentType = "application/json"; 
       this.Response.End(); 
       //TODO : LOGOUT 
      } 
+0

InitUserData()を呼び出すかどうか確認してください。私は_uaUserActionsがnullであると思います –

+0

どのラインで例外がありますか?おそらく 'ConnectionStrng'はヌルです – esiprogrammer

+0

@esiprogrammer here:_uaUserActions.Logout(); –

答えて

0

あなたがUserData.Logout();

UserData.InitUserData(uID, IP);を呼び出す必要があり UserData.logout呼び出すときにnullの _uaUserActionsを持っています
else if (type == 1002) //User Logout 
     { 
      Session["current_user"] = "NoUser"; 

      UserData.InitUserData(uID,IP); //you have to call this befor Logout method. 
      UserData.Logout(); 
      var jss = new JavaScriptSerializer(); 
      this.Response.Write(jss.Serialize(Session["current_user"])); 
      this.Response.ContentType = "application/json"; 
      this.Response.End(); 
      //TODO : LOGOUT 
     } 
0

これは私が解決した方法です:

else if (type == 1002) //User Logout 
      { 
       UserDTO user = (UserDTO)Session["current_user"]; 
       int id = user.ID; 
       string IPja = this.Request.ServerVariables["REMOTE_ADDR"]; 
       UserData.InitUserData(id, IPja); 
       Session["current_user"] = "NoUser"; 

       UserData.Logout(); 
       var jss = new JavaScriptSerializer(); 
       this.Response.Write(jss.Serialize(Session["current_user"])); 
       this.Response.ContentType = "application/json"; 
       this.Response.End(); 
       //TODO : LOGOUT 
      } 
関連する問題

 関連する問題