locked
Certain Users Losing Certain Session Variables? RRS feed

  • Question

  • User446398781 posted

    There are a couple of user's experiences session variable loss after they've clicked a confirm button and their information is email via a relay hosting server. Below, I commented exactly where the session variables get lost.

    What could be causing the session variable loss? So far, this only happens to a few users.

    Part of the email that gets sent out:

            Dim path As String
            Dim logPath As String
            path = Server.MapPath("~/temp/")
            logPath = Server.MapPath("~/temp/Activity")
            path = String.Format("{0}Buildings.txt", path)
            logPath = String.Format("{0}Log.txt", logPath)
            Dim aWriter As New StreamWriter(path, False)
            Dim logWriter As New StreamWriter(logPath, True)
    
            aWriter.Write("The following report was submitted via the Weekly Layer Monitoring Report webpage:")
            aWriter.WriteLine()
         
            aWriter.Write("Week Ending (Saturday PM): ")
            aWriter.Write(Session("WkEnd").ToString)
            aWriter.WriteLine()
            aWriter.Write("Farm Name: ")
            aWriter.Write(Session("FName").ToString)
            aWriter.WriteLine()
            aWriter.Write("Submitter: ")
            aWriter.Write(Session("LName").ToString)
            aWriter.WriteLine()
    
            aWriter.WriteLine("Return Receipt Email Address: " & Session("Email").ToString())
    
           '***for some reason, everything beyond this gets lost?
    
              If Session("BarnNo") <> "" Then
                'write to text file
                aWriter.WriteLine()
                aWriter.Write("Project #1")
                aWriter.WriteLine()
                aWriter.WriteLine()
                aWriter.Write("  Barn/House Number(s):      ")
                aWriter.Write(Session("BarnNo").ToString)
                aWriter.WriteLine()
                aWriter.Write("  Layer Flock Number:        ")
                aWriter.Write(Session("FlockNo").ToString)
                aWriter.WriteLine()
                aWriter.Write("  Hens at Start of Week      ")
                aWriter.WriteLine()
                aWriter.Write("  (1X entry at placement):   ")
                aWriter.Write(Session("HensSW").ToString)
                aWriter.WriteLine()
                aWriter.Write("  Weekly Mortality:          ")
                aWriter.Write(Session("WkMort").ToString)
                aWriter.WriteLine()
    
                aWriter.Write("  Eggs produced this week:")
                aWriter.WriteLine()
                aWriter.Write("      Sunday:                ")
                aWriter.Write(Session("SunEggs").ToString)
                aWriter.WriteLine()
                aWriter.Write("      Monday:                ")
                aWriter.Write(Session("MonEggs").ToString)
                aWriter.WriteLine()
                aWriter.Write("      Tuesday:               ")
                aWriter.Write(Session("TueEggs").ToString)
                aWriter.WriteLine()
                aWriter.Write("      Wednesday:             ")
                aWriter.Write(Session("WedEggs").ToString)
                aWriter.WriteLine()
                aWriter.Write("      Thursday:              ")
                aWriter.Write(Session("ThrEggs").ToString)
                aWriter.WriteLine()
                aWriter.Write("      Friday:                ")
                aWriter.Write(Session("FriEggs").ToString)
                aWriter.WriteLine()
                aWriter.Write("      Saturday:              ")
                aWriter.Write(Session("SatEggs").ToString)
                aWriter.WriteLine()
                aWriter.Write("      Total Eggs:            ")
                aWriter.Write(Session("TtlEggs").ToString)
                aWriter.WriteLine()
                aWriter.WriteLine()
                If Session("FeedDate") <> "" Then
                    aWriter.Write("  Feed Deliveries:")
                    aWriter.WriteLine()
                    aWriter.WriteLine()
                    aWriter.Write("        Date" + "      Formula" + "      Quantity")
                    aWriter.WriteLine()
    
                    aWriter.Write("  " + "1) ")
                    aWriter.Write("  " + Session("FeedDate").ToString + _
                                  "     " + Session("FeedForm").ToString + _
                                  "        " + Session("FeedQty").ToString)
                    aWriter.WriteLine()
                End If
    
                If Session("FeedDateB") <> "" Then
                    aWriter.Write("  " + "2) ")
                    aWriter.Write("  " + Session("FeedDateB").ToString + _
                                  "     " + Session("FeedFormB").ToString + _
                                  "        " + Session("FeedQtyB").ToString)
                    aWriter.WriteLine()
                End If
    
                If Session("FeedDateC") <> "" Then
                    aWriter.Write("  " + "3) ")
                    aWriter.Write("  " + Session("FeedDateB").ToString + _
                                  "     " + Session("FeedFormB").ToString + _
                                  "        " + Session("FeedQtyB").ToString)
                    aWriter.WriteLine()
                End If
    
                If Session("FeedDateD") <> "" Then
                    aWriter.Write("  " + "4) ")
                    aWriter.Write("  " + Session("FeedDateC").ToString + _
                                  "     " + Session("FeedFormC").ToString + _
                                  "        " + Session("FeedQtyC").ToString)
                    aWriter.WriteLine()
                End If
    
                If Session("FeedDateE") <> "" Then
                    aWriter.Write("  " + "5) ")
                    aWriter.Write("  " + Session("FeedDateD").ToString + _
                                  "     " + Session("FeedFormD").ToString + _
                                  "        " + Session("FeedQtyD").ToString)
                    aWriter.WriteLine()
                End If
    
                If Session("FeedDateF") <> "" Then
                    aWriter.Write("  " + "6) ")
                    aWriter.Write("  " + Session("FeedDateF").ToString + _
                                  "     " + Session("FeedFormF").ToString + _
                                  "        " + Session("FeedQtyF").ToString)
                    aWriter.WriteLine()
                End If
    
                If Session("FeedDateG") <> "" Then
                    aWriter.Write("  " + "7) ")
                    aWriter.Write("  " + Session("FeedDateG").ToString + _
                                  "     " + Session("FeedFormG").ToString + _
                                  "        " + Session("FeedQtyG").ToString)
                    aWriter.WriteLine()
                End If
    
                aWriter.WriteLine()
                aWriter.WriteLine()
                aWriter.Write("  Saturday Ending Feed Inv:  ")
                aWriter.Write(Session("SatEndFdInv".ToString))
                aWriter.WriteLine()
                aWriter.Write("  Average Temperature:       ")
                aWriter.Write(Session("AvgTemp".ToString))
                aWriter.WriteLine()
                aWriter.Write("  Case Weight:               ")
                If Session("CaseNo") <> 0.0 Then
                    aWriter.Write(Session("CaseNo").ToString)
                ElseIf Session("CaseNo") <> 0 Then
                    aWriter.Write(Session("CaseNo").ToString)
                End If
                aWriter.WriteLine()
                aWriter.Write("  Cases/Cooler:              ")
                aWriter.Write(Session("CaseCooler".ToString))
                aWriter.WriteLine()
                aWriter.Write("  Water/Gal/Wk:              ")
                aWriter.Write(Session("WtrGalWk".ToString))
                aWriter.WriteLine()
                aWriter.WriteLine()
                aWriter.Write("Comments: ")
                aWriter.Write(Session("Comments".ToString))
                aWriter.WriteLine()
                aWriter.WriteLine()
                aWriter.Write("---------------------------------------------------------")
                aWriter.WriteLine()
            End If
          'and so on....

    Web config file:

     

    <sessionState mode="InProc" timeout="10" />

     

    Monday, March 14, 2011 12:05 PM

Answers

  • User-519136805 posted

    Hi Candy ,

    Here i can see only code to check session is null or not. where you have set these session variables? if you have set these session variables than fine, but please debug your code & check by putting break point that whether you are getting those session values when u execute your code.

    Everything else is looks nice & clear. I dont see any problem here.

    Hope this help !!!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 16, 2011 9:18 AM

All replies

  • User-2010311731 posted

    My guess would be the timeout.  Can you recreate the error within the timeout limit?

     

    Matt

    Monday, March 14, 2011 12:53 PM
  • User446398781 posted

    If it's the timeout that's causing the loss, then why would it still keep some variables but not the others?

    Plus, I have it set to redirect to the main page if the user goes longer than 10 minutes without activity:

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
            HttpContext.Current.Response.AppendHeader("Refresh", Convert.ToString((Session.Timeout * 60)) & "; Url=Default.aspx?Yoursession=expired")
        End Sub
    

     

    Monday, March 14, 2011 1:32 PM
  • User1791120482 posted

    Can you check, whether variables are properly set to the session variables or not in first place.  There might be possibility that you might be adding variables to session conditionally, which is met sometime and sometimes not.

    Tuesday, March 15, 2011 4:01 AM
  • User-519136805 posted

    Hi Candy ,

    Here i can see only code to check session is null or not. where you have set these session variables? if you have set these session variables than fine, but please debug your code & check by putting break point that whether you are getting those session values when u execute your code.

    Everything else is looks nice & clear. I dont see any problem here.

    Hope this help !!!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 16, 2011 9:18 AM