Error while initializing session variable in asp.net

I am having error when initializing the session variable in my asp.net

Here is the value I am passing when I am calling my session function

CustomerIdentityHelper.setCustomerDetailsInSession("0", 0, 0, 0)

Here is the error complete message

Object variable or With block variable not set.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object variable or With block variable not set.


The error is coming on the following line of code
Line 26:         HttpContext.Current.Session("Customer")("Name") = Name

Thanks


Public Shared Sub setCustomerDetailsInSession(ByVal Name As String, ByVal GoldMember As Boolean, ByVal PlatinumMember As Boolean, ByVal CustomerID As Long)
 
        HttpContext.Current.Session("Customer")("Name") = Name
        HttpContext.Current.Session("Customer")("G") = GoldMember
        HttpContext.Current.Session("Customer")("P") = PlatinumMember
        HttpContext.Current.Session("Customer")("CID") = CustomerID
        HttpContext.Current.Session("Customer")("Last") = DateTime.Now
 
    End Sub

Open in new window

LVL 1
shieldguyAsked:
Who is Participating?
 
REA_ANDREWConnect With a Mentor Commented:
HttpContext.Current.Session("Customer")

Make sure that the actual session variable Customer is initialized first, otherwise you are setting a property of an object which does not exist.


Andrew
0
 
shieldguyAuthor Commented:
Thanks Mate
0
All Courses

From novice to tech pro — start learning today.