dcsimg
Results 1 to 18 of 18

Thread: Do you use SESSION state - if not do you turn it off?

  1. #1

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,873

    Do you use SESSION state - if not do you turn it off?

    Does anyone here use session state for storing data on the server? How do you deal with the 20 minute timeout?

    If you do not use session state do you turn it off?

    Anyone using application state objects??

    How about anyone doing advanced logging of what's going on with your IIS app??

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  2. #2

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,873

    Re: Do you use SESSION state - if not do you turn it off?

    Ok - I guess a lack of response kind of indicates an answer.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,610

    Re: Do you use SESSION state - if not do you turn it off?

    I use The Session State to store in process information for the duration for that session only, and the Time-out is about right for me as i want users to be logged out after a certain amount of idle time.

    Not sure that that is helpful though!!


    How about anyone doing advanced logging of what's going on with your IIS app??
    I have my own logging for my Web Service but i am not doing any IIS logging or anything like that which i think is what your asking.
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  4. #4

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,873

    Re: Do you use SESSION state - if not do you turn it off?

    I was speaking about web service logging, actually.'

    What type of logging do you do in your web services?

    How do you make sure that you have a valid person on the other side of your web service calls?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  5. #5
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,610

    Re: Do you use SESSION state - if not do you turn it off?

    I was speaking about web service logging, actually.'

    What type of logging do you do in your web services?
    Its still an incomplete project which is in testing, and so we have just recently introduced logging.

    We log errors obviously, but also some user and request info

    Currently in this first iteration the users can only read and download stuff there is no writing data back yet.

    How do you make sure that you have a valid person on the other side of your web service calls?
    Well the User has to login initially, and we weren't doing any other protection, so if someone knew the methods and the data to pass they could potentially call them.

    However we are just moving to returning a GUID when the User logs in, which then has to be passed into each subsequent call.

    The thing we are still looking at is how we timeout the GUID
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  6. #6
    Fanatic Member namrekka's Avatar
    Join Date
    Feb 2005
    Location
    Netherlands
    Posts
    639

    Re: Do you use SESSION state - if not do you turn it off?

    Well...the questions are a bit broad.

    Quote Originally Posted by szlamany View Post
    Does anyone here use session state for storing data on the server? How do you deal with the 20 minute timeout?

    If you do not use session state do you turn it off?
    Ehh...yes...always. Only data that I need in a session. From client info to captcha-id shopping basket info ,etc. After a timeout the session isn't valid anymore so .....

    Anyone using application state objects??
    You have to look out with this one. After a recycle (occurs once and a while) your data is lost.

    How about anyone doing advanced logging of what's going on with your IIS app??
    I write my own logfiles too. IIS logfiles are great but does not give info about app.


    Again...the questions are a bit broad. Not sure what you want to know. Not all apps running on IIS can be compared as a rule of thumb.

  7. #7

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,873

    Re: Do you use SESSION state - if not do you turn it off?

    I have used SESSION in the past - when I created more standard ASP.Net pages with POSTBACK's and what not.

    In my latest application - more of a AJAX/jQuery web app - I never used SESSION instead choosing to use APPLICATION - but I got here through some strange growth stages.

    My web services need to query the database for PARAMETERS of STORED PROCEDURES prior to executing them. The database-side of my brain said this was too expensive, so I cache them in APPLICATION.

    This function looks first to see if APPLICATION contains an item called g_prmSP - a dictionary of SPROC parameters - to see if a SPROC name is already found. If so, then I grab the parameter template from memory.
    Code:
        Private Sub DetermineParameters(ByRef dcn As SqlConnection, ByRef cmd As SqlCommand, Optional ByRef errorText As String = "")
            Dim blnError As Boolean = False
            Dim blnDoClose As Boolean = False
            Dim blnWriteItBack As Boolean = False
            With Application
                .Lock()
                If .Item("g_prmSP") IsNot Nothing Then
                    g_prmSP = DirectCast(.Item("g_prmSP"), Dictionary(Of String, SqlParameter()))
                End If
                Try
                    If g_prmSP.ContainsKey(cmd.CommandText) Then
                        .UnLock()
                        Dim prm As New SqlParameter
                        For Each prmSP As SqlParameter In g_prmSP(cmd.CommandText)
                            prm = CType(CType(prmSP, ICloneable).Clone(), SqlParameter)
                            cmd.Parameters.Add(prm)
                        Next
                    Else
    The following is the bottom of that function - where I write back the PARAMETER dictionary to the APPLICATION space if I added anything to it.

    Code:
                        Dim prc(cmd.Parameters.Count - 1) As SqlParameter
                        For x As Integer = 0 To cmd.Parameters.Count - 1
                            prc(x) = CType(CType(cmd.Parameters(x), ICloneable).Clone(), SqlParameter)
                        Next
                        g_prmSP.Add(cmd.CommandText, prc)
                    End If
                Catch ex As Exception
                    blnError = True
                    errorText = ex.Message.Replace("""", "'").Replace("\", "\\")
                    LogOutput("DetermineParameters: " & cmd.CommandText & " " & ex.Message)
                Finally
                    If blnDoClose Then
                        If dcn.State = ConnectionState.Open Then dcn.Close()
                    End If
                End Try
                If blnWriteItBack Then
                    .Item("g_prmSP") = g_prmSP
                    .UnLock()
                End If
            End With
        End Sub
    I didn't care that the APPLICATION might recycle because all that meant is the CACHE got lost and needed to be re-built. Not too expensive to do on each FIRST SPROC call.

    I also store the NAME of the current LOG file for my web services in APPLICATION. Again I didn't care if that got lost.

    Code:
        Private Sub LogOutput(ByRef LogText As String)
            Dim strLogFile As String = ""
            With Application
                .Lock()
                If .Item("g_logfile") IsNot Nothing Then
                    strLogFile = .Item("g_logfile").ToString()
                Else
                    strLogFile = "WebService_" & DateTime.Now.ToString("yyyyMMddhhmmss", System.Globalization.CultureInfo.GetCultureInfo("en-US")) & ".log"
                    .Item("g_logfile") = strLogFile
                End If
                Dim strLogFolder As String = System.Web.Configuration.WebConfigurationManager.AppSettings("logfolder")
                strLogFile = Path.Combine(strLogFolder, strLogFile)
                Using fs1 As FileStream = New FileStream(strLogFile, FileMode.Append, FileAccess.Write)
                    Using s1 As StreamWriter = New StreamWriter(fs1)
                        s1.Write(DateTime.Now.ToString & ": " & LogText & vbCrLf)
                        's1.Write(LogText & vbCrLf)
                        s1.Close()
                        fs1.Close()
                    End Using
                End Using
                .UnLock()
            End With
        End Sub
    By doing it this way any call to LOGOUTPUT, regardless of what USER/SESSION is calling the backend, gets logged to a single physical log file on my IIS box.

    For WEB METHOD security I also produce a GUID upon the initial login of the user. And I store this in APPLICATION space.

    Code:
                    If UserValid Then
                        If credDB <> "" Then
                            .NewObject("db", credDB)
                            .Seperate()
                        End If
                        strMessage = nGuid.ToString
                        With Application
                            .Lock()
                            If .Item("g_GUIDS") IsNot Nothing Then
                                g_GUIDS = DirectCast(.Item("g_GUIDS"), Dictionary(Of String, Dictionary(Of String, String)))
                            End If
                            g_GUIDS.Add(strMessage, New Dictionary(Of String, String))
                            g_GUIDS(strMessage).Add("status", "success")
                            g_GUIDS(strMessage).Add("logindate", Date.Now.ToShortDateString)
                            g_GUIDS(strMessage).Add("logintime", Date.Now.ToLongTimeString)
                            .Item("g_GUIDS") = g_GUIDS
                            .UnLock()
                        End With
                    Else
                        If strSuccess <> "" Then
                            strSuccess = ""
                            strMessage = "<br />Log in failure!"
                            LogOutput("Log in failure (Not UserValid): " & loginUsername)
                        End If
                    End If
    Now I am concerned about APPLICATION recycle - which can happen at any time.

    Note - this can happen in the middle of a SESSION causing SESSION variable loss for you all using SESSION, if I am not mistaken.

    To handle APPLICATION recycle - in GLOBAL.asax - you simply handle the APPLICATION_START and APPLICATION_END events.

    A bit of setup before I show those events. I log errors and events in GLOBAL.asax to a GLOBAL.LOG file

    Code:
        Private Sub LogOutput(ByRef LogText As String)
            Dim strLogFile As String = "Global.log"
            With Application
                .Lock()
                Dim strLogFolder As String = System.Web.Configuration.WebConfigurationManager.AppSettings("logfolder")
                strLogFile = Path.Combine(strLogFolder, strLogFile)
                Using fs1 As FileStream = New FileStream(strLogFile, FileMode.Append, FileAccess.Write)
                    Using s1 As StreamWriter = New StreamWriter(fs1)
                        s1.Write(DateTime.Now.ToString & ": " & LogText & vbCrLf)
                        s1.Close()
                        fs1.Close()
                    End Using
                End Using
                .UnLock()
            End With
        End Sub
    This post is getting too long - I'll go onto a second post to finish this...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  8. #8

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,873

    Re: Do you use SESSION state - if not do you turn it off?

    ...this is a continuation of the prior post...

    Now in APPLICATION_END I have to write the GUID's that are currently logged in to a TEXT file (Restart_data.txt).

    Code:
        Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
            ' Code that runs on application shutdown
            LogOutput("Application End...")
            Try
                With Application
                    .Lock()
    
                    LogDirect("AppStart=" & .Item("AppStart").ToString())
    
                    If .Item("g_prmSP") IsNot Nothing Then
                        Dim _prmSP As New Dictionary(Of String, SqlParameter())
                        _prmSP = DirectCast(.Item("g_prmSP"), Dictionary(Of String, SqlParameter()))
                        LogDirect("g_prmSP.Count=" & _prmSP.Count.ToString())
                    Else
                        LogDirect("g_prmSP=nothing")
                    End If
    
                    If .Item("g_GUIDS") IsNot Nothing Then
                        Dim _GUIDS As New Dictionary(Of String, Dictionary(Of String, String))
                        _GUIDS = DirectCast(.Item("g_GUIDS"), Dictionary(Of String, Dictionary(Of String, String)))
                        LogDirect("g_GUIDS.Count=" & _GUIDS.Count.ToString())
                        Dim strStartFile As String = "Restart_data.txt"
                        Dim strLogFolder As String = System.Web.Configuration.WebConfigurationManager.AppSettings("logfolder")
                        strStartFile = Path.Combine(strLogFolder, strStartFile)
                        If File.Exists(strStartFile) Then
                            Dim strStartNew As String = "Restart_notused_" & DateTime.Now.ToString("yyyymmddhhMMss") & ".txt"
                            File.Move(strStartFile, strStartNew)
                        End If
                        Dim appLatest As DateTime = CDate(.Item("AppStart"))
                        For Each sguid As String In _GUIDS.Keys
                            Dim sgD As String = "", sgT As String = ""
                            For Each sgsetting As String In _GUIDS.Item(sguid).Keys
                                If sgsetting = "logindate" Then
                                    sgD = _GUIDS.Item(sguid).Item(sgsetting)
                                ElseIf sgsetting = "logintime" Then
                                    sgT = _GUIDS.Item(sguid).Item(sgsetting)
                                End If
                            Next
                            If sgD <> "" AndAlso sgT <> "" Then
                                Dim sgDT As DateTime = CDate(sgD & " " & sgT)
                                If sgDT > appLatest Then
                                    appLatest = sgDT
                                End If
                            End If
                        Next
                        Using fs1 As FileStream = New FileStream(strStartFile, FileMode.Create, FileAccess.Write)
                            Using s1 As StreamWriter = New StreamWriter(fs1)
                                's1.Write(.Item("AppStart").ToString() & vbCrLf)
                                s1.Write(appLatest.ToString() & "~@@~" & .Item("AppStart").ToString() & vbCrLf)
                                For Each sguid As String In _GUIDS.Keys
                                    For Each sgsetting As String In _GUIDS.Item(sguid).Keys
                                        s1.Write(sguid & "~~" & sgsetting & "=" & _GUIDS.Item(sguid).Item(sgsetting) & vbCrLf)
                                    Next
                                Next
                                s1.Close()
                                fs1.Close()
                            End Using
                        End Using
                    Else
                        LogDirect("g_GUIDS=nothing")
                    End If
    
                    .UnLock()
                End With
            Catch ex As Exception
                LogOutput("Application End error: " & ex.Message)
            End Try
            LogOutput("Application End")
        End Sub
    Then on the flip side I load this GUID text file in APPLICATION_START. There is logic here to timeout GUID's that have no activity for a real long time

    Code:
        Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
            ' Code that runs on application startup
            Dim strAppStart As String = DateTime.Now.ToString()
            LogOutput("Application Start..." & strAppStart)
            Try
                With Application
                    .Lock()
    
                    .Item("AppStart") = strAppStart
    
                    Dim _GUIDS As New Dictionary(Of String, Dictionary(Of String, String))
    
                    Dim strStartFile As String = "Restart_data.txt"
                    Dim strLogFolder As String = System.Web.Configuration.WebConfigurationManager.AppSettings("logfolder")
                    strStartFile = Path.Combine(strLogFolder, strStartFile)
                    If File.Exists(strStartFile) Then
                        Dim restartUsed As String = DateTime.Now.ToString("yyyyMMddhhmmss")
                        Dim strStartNew As String = "Restart_used_" & restartUsed & ".txt"
                        strStartNew = Path.Combine(strLogFolder, strStartNew)
                        File.Move(strStartFile, strStartNew)
                        Using sr As StreamReader = New StreamReader(strStartNew)
                            Dim gotDate As Boolean = False
                            Dim keepRunning As Boolean = True
                            Dim skipList As New List(Of String)
                            Do While keepRunning AndAlso sr.Peek() >= 0
                                If Not gotDate Then
                                    Dim sDate As String = sr.ReadLine()
                                    If sDate.Contains("~@@~") Then
                                        sDate = sDate.Substring(0, sDate.IndexOf("~@@~"))
                                    End If
                                    Dim dDate As DateTime = CDate(sDate)
                                    Dim dNow As DateTime = Now
                                    Select Case DateDiff(DateInterval.Day, dDate, dNow)
                                        Case 0
                                            LogDirect("Restart Data Accepted: " & sDate)
                                        Case 1
                                            If DateDiff(DateInterval.Hour, dDate, dNow) <= 4 Then
                                                LogDirect("Restart Data Accepted: " & sDate)
                                            Else
                                                LogDirect("Restart Data Expired: " & sDate)
                                                keepRunning = False
                                            End If
                                        Case Else
                                            LogDirect("Restart Data Expired: " & sDate)
                                            keepRunning = False
                                    End Select
                                    gotDate = True
                                Else
                                    Dim sgInfo As String = sr.ReadLine()
                                    Dim sguid As String = ""
                                    If sgInfo.Contains("~~") Then
                                        Dim cp As Integer = sgInfo.IndexOf("~~")
                                        If cp <> 0 Then
                                            sguid = sgInfo.Substring(0, cp)
                                            sgInfo = sgInfo.Substring(cp + 2)
                                        End If
                                    End If
                                    If sguid <> "" Then
                                        Dim sgi As String = ""
                                        Dim sgv As String = ""
                                        Dim cp As Integer = sgInfo.IndexOf("=")
                                        If cp <> 0 Then
                                            sgi = sgInfo.Substring(0, cp)
                                            sgv = sgInfo.Substring(cp + 1)
                                        End If
                                        If _GUIDS.ContainsKey(sguid) Then
                                            If sgi = "logindate" AndAlso DateDiff(DateInterval.Day, CDate(sgv), Now) > 2 Then
                                                skipList.Add(sguid)
                                                _GUIDS.Remove(sguid)
                                            Else
                                                _GUIDS.Item(sguid).Add(sgi, sgv)
                                            End If
                                        ElseIf Not skipList.Contains(sguid) Then
                                            Dim nl As New Dictionary(Of String, String)
                                            nl.Add("restart_" & restartUsed, strAppStart)
                                            nl.Add(sgi, sgv)
                                            _GUIDS.Add(sguid, nl)
                                        End If
                                    End If
                                End If
                            Loop
                        End Using
                    End If
                    LogDirect("g_GUIDS.Count=" & _GUIDS.Count.ToString())
                    .Item("g_GUIDS") = _GUIDS
                    .UnLock()
                End With            
            Catch ex As Exception
                LogOutput("Application Start error: " & ex.Message)
            End Try
            LogOutput("Application Start")
        End Sub
    It's some ugly code - might make more sense to also show how the GUID's look in the TEXT file

    Code:
    2/2/2016 10:28:07 AM~@@~2/2/2016 10:17:17 AM
    2b007492-9cd0-4cdf-9331-39ee0884b990~~status=success
    2b007492-9cd0-4cdf-9331-39ee0884b990~~logindate=2/2/2016
    2b007492-9cd0-4cdf-9331-39ee0884b990~~logintime=10:17:48 AM
    2b007492-9cd0-4cdf-9331-39ee0884b990~~LastActivity=EditService
    2b007492-9cd0-4cdf-9331-39ee0884b990~~LastTime=2/2/2016 10:23:58 AM
    bf8084d1-6c18-406b-8bba-d62d6eb091a6~~status=success
    bf8084d1-6c18-406b-8bba-d62d6eb091a6~~logindate=2/2/2016
    bf8084d1-6c18-406b-8bba-d62d6eb091a6~~logintime=10:28:07 AM
    bf8084d1-6c18-406b-8bba-d62d6eb091a6~~LastActivity=OperatorService
    bf8084d1-6c18-406b-8bba-d62d6eb091a6~~LastTime=2/2/2016 10:28:19 AM
    Now to wrap up the whole GUID story I do this in each and every web method I have

    Code:
        <WebMethod()> _
        <ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=False)> _
        Public Function LookupService(ByVal fromwho As String, ByVal fromddtype As String, ByVal toddtype As String, ByVal lookup As String _
                                                                                                        , ByVal lookupextra As Dictionary(Of String, String) _
                                                                                                        , ByVal sguid As String _
                                                                                                        , ByVal username As String) As String
    
            Dim rtnString As String = ""
    
            Try
                If checkGuid(sguid) Then
                    Dim credDB As String = ""
    .
    .
    .
                    End With
    
                    rtnString = JsonMaker.GetJson()
    
                Else
                    rtnString = "{""LoginRequired"": true}"
                    LogOutput("GUID not found (LookupService): " & username)
                End If
            Catch ex As Exception
                LogOutput(ex.Message & " (LookupService): " & username)
            End Try
    
            Return rtnString
    
        End Function
    And the function checkGuid looks like this:

    Code:
        Private Function checkGuid(sguid As String, Optional recordact As Boolean = False, Optional swhat As String = "") As Boolean
            Dim rtnStatus As Boolean = False
            Dim gotGuids As Boolean = False
            Dim foundGuid As Boolean = False
            Dim errMsg As String = ""
            Try
                If recordact Then
                    With Application
                        .Lock()
                        If .Item("g_GUIDS") IsNot Nothing Then
                            g_GUIDS = DirectCast(.Item("g_GUIDS"), Dictionary(Of String, Dictionary(Of String, String)))
                            gotGuids = True
                        End If
                        If gotGuids Then
                            Dim dl As Dictionary(Of String, String) = DirectCast(g_GUIDS(sguid), Dictionary(Of String, String))
                            dl("LastActivity") = swhat
                            dl("LastTime") = DateTime.Now.ToString()
                            foundGuid = True
                            .Item("g_GUIDS") = g_GUIDS
                        End If
                        .UnLock()
                    End With
                Else
                    With Application
                        .Lock()
                        If .Item("g_GUIDS") IsNot Nothing Then
                            g_GUIDS = DirectCast(.Item("g_GUIDS"), Dictionary(Of String, Dictionary(Of String, String)))
                            gotGuids = True
                        End If
                        .UnLock()
                    End With
                    If g_GUIDS.ContainsKey(sguid) Then
                        foundGuid = True
                    End If
                End If
            Catch ex As Exception
                errMsg = ex.Message
                gotGuids = False
            End Try
            rtnStatus = foundGuid
            Return rtnStatus
        End Function

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  9. #9
    Fanatic Member namrekka's Avatar
    Join Date
    Feb 2005
    Location
    Netherlands
    Posts
    639

    Re: Do you use SESSION state - if not do you turn it off?

    I had problems with the APPLICATION_END event caused with a "recycle". It didn't generate an event at all in this case. Not sure it was IIS or me. So I moved from this. I stored my data (some settings) in a text file and read them back when needed. Care should be taken where to store this file.
    Last edited by namrekka; Feb 4th, 2016 at 05:06 AM. Reason: Typos

  10. #10

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,873

    Re: Do you use SESSION state - if not do you turn it off?

    I've never had a report of the APPLICATION_END event not running at any of my client sites. That would cause all users of that site to lose GUID's and force them all to re-login.

    I would have gotten reports of this happening if it ever did.

    And I don't timeout GUID's for 48+ hours. My users are used to really long login sessions before I time them out.

    The initial reason I posted this thread is because I had put some code in the SESSION_START and SESSION_END events in Global.asax and notice that they were happening constantly - every 20 minutes.

    Code:
        Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
            LogOutput("Session Start")
            ' Code that runs when a new session is started
        End Sub
    
        Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
            LogOutput("Session End")
            ' Code that runs when a session ends. 
            ' Note: The Session_End event is raised only when the sessionstate mode
            ' is set to InProc in the Web.config file. If session mode is set to StateServer 
            ' or SQLServer, the event is not raised.
        End Sub
    Since I never use SESSION - from what I can see in my own code - I'm thinking of turning it off so the events do not raise. SESSION start's are expensive from what I've read (both time and memory).

    Code:
    1/27/2016 11:58:56 AM: Session Start
    1/27/2016 11:59:00 AM: Session End
    1/27/2016 12:03:56 PM: Session Start
    1/27/2016 12:04:01 PM: Session End
    1/27/2016 12:08:56 PM: Session Start
    1/27/2016 12:09:01 PM: Session End
    1/27/2016 12:09:42 PM: Session Start
    1/27/2016 12:09:42 PM: Session End
    1/27/2016 12:09:42 PM: Session End
    1/27/2016 12:09:42 PM: Session End
    1/27/2016 12:09:42 PM: Session End
    1/27/2016 12:09:42 PM: Session End
    1/27/2016 12:09:42 PM: Application End...
    1/27/2016 12:09:42 PM: AppStart=1/27/2016 11:34:20 AM
    1/27/2016 12:09:42 PM: g_prmSP.Count=22
    1/27/2016 12:09:42 PM: g_GUIDS.Count=60
    1/27/2016 12:09:42 PM: Application End
    1/27/2016 12:10:28 PM: Application Start...1/27/2016 12:10:28 PM
    1/27/2016 12:10:28 PM: Restart Data Accepted: 1/27/2016 11:34:20 AM
    1/27/2016 12:10:28 PM: g_GUIDS.Count=60
    1/27/2016 12:10:28 PM: Application Start
    1/27/2016 12:13:57 PM: Session Start
    1/27/2016 12:16:27 PM: Session Start
    1/27/2016 12:18:58 PM: Session Start
    1/27/2016 12:23:58 PM: Session Start
    1/27/2016 12:28:58 PM: Session Start
    1/27/2016 12:33:59 PM: Session Start
    1/27/2016 12:34:00 PM: Session End
    1/27/2016 12:38:41 PM: Session End
    1/27/2016 12:39:00 PM: Session Start
    1/27/2016 12:39:01 PM: Session End
    1/27/2016 12:44:00 PM: Session Start
    1/27/2016 12:44:01 PM: Session End
    1/27/2016 12:49:01 PM: Session Start
    1/27/2016 12:49:01 PM: Session End
    1/27/2016 12:54:01 PM: Session End
    1/27/2016 12:54:02 PM: Session Start
    1/27/2016 12:59:01 PM: Session End
    1/27/2016 12:59:02 PM: Session Start
    1/27/2016 1:04:02 PM: Session End
    1/27/2016 1:04:03 PM: Session Start
    1/27/2016 1:09:02 PM: Session End
    1/27/2016 1:09:03 PM: Session Start
    1/27/2016 1:14:02 PM: Session End
    1/27/2016 1:14:03 PM: Session Start
    1/27/2016 1:19:02 PM: Session End
    1/27/2016 1:19:03 PM: Session Start
    1/27/2016 1:24:03 PM: Session Start
    1/27/2016 1:24:22 PM: Session End
    1/27/2016 1:29:03 PM: Session Start
    1/27/2016 1:29:23 PM: Session End
    1/27/2016 1:34:04 PM: Session Start
    1/27/2016 1:34:23 PM: Session End
    1/27/2016 1:39:03 PM: Session End
    1/27/2016 1:39:04 PM: Session Start
    1/27/2016 1:44:03 PM: Session End
    1/27/2016 1:44:04 PM: Session Start
    1/27/2016 1:49:03 PM: Session End
    1/27/2016 1:49:04 PM: Session Start
    1/27/2016 1:54:05 PM: Session Start
    1/27/2016 1:54:24 PM: Session End
    1/27/2016 1:59:05 PM: Session Start
    1/27/2016 1:59:24 PM: Session End
    1/27/2016 2:04:05 PM: Session Start
    1/27/2016 2:04:24 PM: Session End
    1/27/2016 2:09:05 PM: Session Start
    1/27/2016 2:09:24 PM: Session End
    1/27/2016 2:14:06 PM: Session Start
    1/27/2016 2:14:24 PM: Session End
    1/27/2016 2:19:07 PM: Session Start
    1/27/2016 2:19:24 PM: Session End
    1/27/2016 2:24:08 PM: Session Start
    Last edited by szlamany; Feb 4th, 2016 at 09:37 AM.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  11. #11
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    5,625

    Re: Do you use SESSION state - if not do you turn it off?

    Depends on the project.
    If I am able to hold data on the client then nice. Else, since I haven't used APPLICATION, it's either session or cookies(for small amounts of data).
    If I remember correctly asp.net membership uses session so if I'm to go for that I can't avoid it.
    Session is memory read-write so it's fast but , for example in the latest project I have to pass about 100-500kb of data per call of a user and maintain them for 30 minutes and the calls are about 1000 for these minutes so I may end up to 3 to 15GB of memory usage.
    So I'm thinking of alternatives, maybe session to SQL or If I have time(that's is running a little low), convert all the calls so they can be client side Ajax enable and store to JQuery.Data. Haven't done that again, so not sure about the behavior but will see.
    All in all everything but the viewstate
    Slow as hell.

  12. #12

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,873

    Re: Do you use SESSION state - if not do you turn it off?

    Does that mean you up'd the SESSION timeout to 30 minutes?

    Is that data specific to the user? Any of it shared?

    If any of it is shared you can consider APPLICATION.

    Even if some of it's not shared you can still use APPLICATION.

    APPLICATION lives for a lot longer then the default of 20 minutes that SESSION does.

    ----------------------

    I'm guessing you can't save it on the CLIENT side because you have POSTBACK's - is that right?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  13. #13
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    5,625

    Re: Do you use SESSION state - if not do you turn it off?

    Yep, 30 minutes is fine, probably can go with 15-20 minutes.
    Unfortunately it's shared, I was also considering cache initially for not shared but we ended up with shared data for various reasons.
    The main problem is the amount of data vs connections.It will probably be troublesome for so much data to stay in memory so I was thinking about external cache or session with SQL but I'm not sure if we are going to allow any local database to be used (trying something on the fly here was suggested). So I was thinking if (and that is a big if) I have time, I can make all the WCF service to be Ajax enabled so someone can use Jquery.data .
    This will run on asp.net, Iphone, Android and will be externally available for developers so as you can see, loooot of server memory usage there
    BTW have you ever worked with Jquery.data? Would appreciate any feedback and in general any feedback.
    The main problem here is that I am stuck with the WCF "No connection could be made because the target machine actively refused it ", we were discussing a couple of thread's back, and I'm using up the time I have available, waiting to go to Head Office and see our admin for the issue. So I'm not sure if I could turn everything Ajax cuz time is short.
    Slow as hell.

  14. #14

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,873

    Re: Do you use SESSION state - if not do you turn it off?

    I really like making my own web services and using straight Ajax and jQuery to build and fill the DOM.

    All my backend web services are generic - all the binding happens in the JavaScript.

    I rarely change web services - really only enhancements when I need to exploit some new feature in the front end.

    I also support Android devices making POST's to web services on the same IIS platform.

    I get lots and lots of POST's - a user will select a record - getting a huge grid of data returned (if you ever have need of a grid - check out SlickGrid.js). Then they select a row - open a detail panel to edit that record - more Ajax calls for that. Some fields require more Ajax calls to validate or request additional information.

    Then a SAVE operation.

    Standard maintenance - just dozens and dozens of simultaneous users so Ajax calls are flying in.

    That's why I am exploring turning off SESSION. It's a place I do not need to store data so the expense of making a session as they timeout every 20 minutes anyway is just a huge waste. I do not need the memory waste or the CPU cycle waste.

    Back to your issues.

    If the data is shared - meaning to me that it's common among all the connected users - why are you using SESSION instead of APPLICATION.

    They are the same thing only different SCOPE.

    If you have the "same" data being "saved" in different user's SESSION space then you should reconsider that choice.

    I have no experience with WCF and really can't help with that connection refusal issue. If I understood more of what the basics were I could do a bit searching around...

    All my Ajax calls are POST's to the SAME IP address - usually port 443 for some added security.

    Does WCF act more like traditional ASP.Net with partial POSTBACK's and what not?

    I have not used jQuery.data - sounds interesting. Most of my data resides in the browser in a standard ARRAY of OBJECTS. That is what most JavaScript and jQuery shareware UI stuff requires.

    I've gone crazy making a JavaScript class to manage these ARRAY's - SORT'ing and multi-column sorting, row filtering, grid summary and grid graphing (with jqPlot.js - a really incredible plotting tool).

    And any setup a user makes can be saved and shared and called up later - basically a report writer tool for the user.

    My users, for example, expect to download 30,000 - 40,000 rows of fiscal data in JavaScript and then play with it using this data class.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  15. #15
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    5,625

    Re: Do you use SESSION state - if not do you turn it off?

    Hi.
    Yes I actually meant the opposite. The data is NOT shared among users. It's unique to every scope.
    WCF actually have 2 implementation that I'm aware of. One will accept call's from applications or web app's but will not support AJAX calls and the other will support Ajax calls.
    Haven't been able to do that in one take as the plague of WCF is it's web.config or application.config. It is so very complex that a simple mistake can make it crash.
    I have made the standard WCF without AJAX and (if you remember) I was struggling to make an AJAX WCF and finally did it but it requires a different web.config setup, so I cannot combine.
    So using AJAX will require to change the implemented functions to be AJAX acceptance functions and the return objects to return AJAX enabled JSON or XML objects. All the other implementation stays the same ,except the web config and a hack on the Application_BeginRequest. That is very tricky so I made a codebank example back then. Let me......Uh, here: http://www.vbforums.com/showthread.p...d-CORS-enabled
    Slow as hell.

  16. #16
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,610

    Re: Do you use SESSION state - if not do you turn it off?

    That's why I am exploring turning off SESSION. It's a place I do not need to store data so the expense of making a session as they timeout every 20 minutes anyway is just a huge waste. I do not need the memory waste or the CPU cycle waste.
    Well i cant say i have ever tried, we actually want our sessions to time out fairly quickly, and we don't need any data to persist any longer then those short sessions.

    Let us know how you get on, you never know what you do today maybe we will have a need in the future
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  17. #17
    Fanatic Member namrekka's Avatar
    Join Date
    Feb 2005
    Location
    Netherlands
    Posts
    639

    Re: Do you use SESSION state - if not do you turn it off?

    Quote Originally Posted by szlamany View Post
    ......If the data is shared - meaning to me that it's common among all the connected users - why are you using SESSION instead of APPLICATION........
    Now its clear to me.

    But do you get an application-end event caused by a recycle?

  18. #18

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,873

    Re: Do you use SESSION state - if not do you turn it off?

    Yes - you get an APPLICATION END event - where I post all my APPLICATION data to a text file. And then on the APPLICATION START event I re-load the APPLICATION data from the text file. This has been working seamlessly for many, many months.

    See post #8 for my code in those two events.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width