locked
Set a session in DLL RRS feed

  • Question

  • Trying to set a session in a DLL. I'm not sure if that's different than regular code but its giving an error currently. Here is the code:

    Error:

    Object reference not set to an instance of an object.

    Property:

     public bool Authenticated
            {
                get
                {
                    return (Boolean)HttpContext.Current.Session["Authenticated"];
                }
                set
                {
                    HttpContext.Current.Session["Authenticated"] = value;
                }
            }

    Function:

    private bool Authenticate()
            {
                try
                {
                    if (Authenticated == false)
                    {
                        //Try to Authenticate Token
                        System.Net.ServicePointManager.Expect100Continue = false;
    
                        //return true if authenticate token is not empty (no error)
                        bool callAuthenticate = false;
    
                        if (Config.Session != null && Config.Session["AHASSOAuthenticateToken"] != null) //jth Added check on Config.Session 8/14/2013 Case #143649 Per AHA/CF Request
                        {
    
                            this.AuthenticateToken = (token)Config.Session["AHASSOAuthenticateToken"];
    
                            if (!isTokenValid(AuthenticateToken))
                                callAuthenticate = true;
                        }
                        else
                            callAuthenticate = true;
    
                        if (callAuthenticate)
                        {
                            string username = Config.SystemOptions["AHASSOAccountusername"].ToString();
                            string password = Config.SystemOptions["AHASSOAccountpassword"].ToString();
                            //string uri = Config.SystemOptions["AHASSOWebServiceURL"].ToString();
                            Authenticate(username, password, uri);
                        }
    
                        if (this.AuthenticateToken != null)
                            Authenticated = true;
                        //return true;
                        else
                            Authenticated = false;
                        //return false;
                    }
    
                    return Convert.ToBoolean(Authenticated);
                }
                catch (Exception ex)
                {
                    dynamic _Method = Convert.ToString(System.Reflection.MethodBase.GetCurrentMethod().Name);
                    dynamic _Class = Convert.ToString(this.GetType().Name);
                    string _Exception = Convert.ToString(ex.ToString());
                    string _Exception_Information = "Class: " + _Class + " Method:" + _Method;
    
                    //AHA_Utilities.Log_Exception(_Exception_Information, _Exception);
                    return false;
                }
            }


    • Edited by old_School Wednesday, March 15, 2017 7:56 PM
    • Moved by CoolDadTx Thursday, March 16, 2017 2:13 PM ASP.NET related
    Wednesday, March 15, 2017 7:49 PM

Answers

  • Hi old_School,

    Thank you for posting here.

    For your question, what is your project?

    You could refer to the MSDN article HttpContext.Session Property.

    If your question is more related to ASP.NET, you could post a new thread in ASP.NET forum.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by old_School Tuesday, April 4, 2017 6:56 PM
    Thursday, March 16, 2017 2:18 AM

All replies

  • Hi,

    Could you point out which line of code is giving the error?

    Wednesday, March 15, 2017 10:41 PM
  • Hi old_School,

    Thank you for posting here.

    For your question, what is your project?

    You could refer to the MSDN article HttpContext.Session Property.

    If your question is more related to ASP.NET, you could post a new thread in ASP.NET forum.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by old_School Tuesday, April 4, 2017 6:56 PM
    Thursday, March 16, 2017 2:18 AM
  • Please post questions related to web development in the ASP.NET forums.
    Thursday, March 16, 2017 2:13 PM