1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Frequently session timeouts

Discussion in 'C#' started by mlungisi, May 20, 2010.

  1. #1
    Hi there, I need help with session timeouts. I’m new in the ASP world and just took over from someone as a junior web developer/webmaster.

    The problem is with user session on the site, they get kicked out now and then and it does the same thing to me with our testing account and sometimes refuses to log me out. This is really frustrating customers and am on a hot seat as I cannot figure it out.

    My Global.asa

    <SCRIPT LANGUAGE=VBScript RUNAT=Server>

    'You can add special event handlers in this file that will get run automatically when
    'special Active Server Pages events occur. To create these handlers, just create a
    'subroutine with a name from the list below that corresponds to the event you want to
    'use. For example, to create an event handler for Session_OnStart, you would put the
    'following code into this file (without the comments):

    Sub Session_OnStart

    'FrontPage_StartSession '==FrontPage Generated==
    'Session("Connection") = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=D:\Data\MycompanyName.mdb"
    'Session("Connection") = "DSN=oMycompanyName;User ID=****;PWD="
    'Session("Connection") = "oMycompanyName"
    'Session("Connection") = "driver={Microsoft Access Driver (*.mdb)};dbq=G:\Inetpub\wwwroot\WebSites\MycompanyName.co.za\database\MycompanyName.mdb;;"


    randomize
    timepart = Day(Now()) & Month(Now()) & Year(Now()) & hour(Time())
    timepart = timepart & (100001 * rnd) * rnd(timepart)
    session("order_id") = Mid(Replace(timepart, ".", ""), 1, 14 )

    'Session("Test") = "Test"
    End Sub
    Sub FrontPage_StartSession
    On Error Resume Next
    if Len(Application("FrontPage_VRoot")) > 0 then Exit Sub

    sFile = "global.asa"
    sRootPath = Request.ServerVariables("APPL_PHYSICAL_PATH")
    if Left(sRootPath,1) = "/" then sSep = "/" else sSep = "\"
    if Right(sRootPath,1) <> sSep then sRootPath = sRootPath & sSep
    sRootPath = sRootPath & sFile

    ' discover the VRoot for the current page;
    ' walk back up VPath until we match VRoot
    Vroot = Request.ServerVariables("PATH_INFO")
    iCount = 0
    do while Len(Vroot) > 1
    idx = InStrRev(Vroot, "/")
    if idx > 0 then
    Vroot = Left(Vroot,idx)
    else
    ' error; assume root web
    Vroot = "/"
    end if
    if Server.MapPath(Vroot & sFile) = sRootPath then exit do
    if Right(Vroot,1) = "/" then Vroot = Left(Vroot,Len(Vroot)-1)
    iCount = iCount + 1
    if iCount > 100 then
    ' error; assume root web
    Vroot = "/"
    exit do
    end if
    loop
    ' map all URL= attributes in _ConnectionString variables
    Application.Lock
    if Len(Application("FrontPage_VRoot")) = 0 then
    Application("FrontPage_VRoot") = Vroot
    UrlVarArray = Application("FrontPage_UrlVars")
    for i = 0 to UBound(UrlVarArray)
    if Len(UrlVarArray(i)) > 0 then FrontPage_MapUrl(UrlVarArray(i))
    next
    end if
    Application.Unlock
    End Sub
    Sub FrontPage_MapUrl(AppVarName)
    ' convert URL attribute in conn string to absolute file location
    strVal = Application(AppVarName)
    strKey = "URL="
    idxStart = InStr(strVal, strKey)
    If idxStart = 0 Then Exit Sub
    strBefore = Left(strVal, idxStart - 1)
    idxStart = idxStart + Len(strKey)
    idxEnd = InStr(idxStart, strVal, ";")
    If idxEnd = 0 Then
    strAfter = ""
    strURL = Mid(strVal, idxStart)
    Else
    strAfter = ";" & Mid(strVal, idxEnd + 1)
    strURL = Mid(strVal, idxStart, idxEnd - idxStart)
    End If
    strOut = strBefore & Server.MapPath(Application("FrontPage_VRoot") & strURL) & strAfter
    Application(AppVarName) = strOut
    End Sub

    'EventName Description
    'Session_OnStart Runs the first time a user runs any page in your application
    'Session_OnEnd Runs when a user's session times out or quits your application
    'Application_OnStart Runs once when the first page of your application is run for the first time by any user
    'Application_OnEnd Runs once when the web server shuts down

    </SCRIPT>

    <SCRIPT LANGUAGE=VBScript RUNAT=Server>
    Sub Application_OnStart
    '==FrontPage Generated - startspan==
    Dim FrontPage_UrlVars(6)
    '--Project Data Connection
    Application("new_page_1_ConnectionString") = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=URL=fpdb/DealerSurvey.mdb"
    FrontPage_UrlVars(0) = "new_page_1_ConnectionString"
    Application("new_page_1_ConnectionTimeout") = 15
    Application("new_page_1_CommandTimeout") = 30
    Application("new_page_1_CursorLocation") = 3
    Application("new_page_1_RuntimeUserName") = ""
    Application("new_page_1_RuntimePassword") = ""
    '--Project Data Connection
    Application("cat_order_ConnectionString") = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=URL=fpdb/cat_order.mdb"
    FrontPage_UrlVars(1) = "cat_order_ConnectionString"
    Application("cat_order_ConnectionTimeout") = 15
    Application("cat_order_CommandTimeout") = 30
    Application("cat_order_CursorLocation") = 3
    Application("cat_order_RuntimeUserName") = ""
    Application("cat_order_RuntimePassword") = ""
    '--Project Data Connection
    Application("Database1_ConnectionString") = "DSN=Xtreme Sample Database;DRIVER={Microsoft Access Driver (*.mdb)}"
    Application("Database1_ConnectionTimeout") = 15
    Application("Database1_CommandTimeout") = 30
    Application("Database1_CursorLocation") = 3
    Application("Database1_RuntimeUserName") = ""
    Application("Database1_RuntimePassword") = ""
    '--Project Data Connection
    Application("SurveyDatabase_ConnectionString") = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=URL=fpdb/Survey.mdb"
    FrontPage_UrlVars(3) = "SurveyDatabase_ConnectionString"
    Application("SurveyDatabase_ConnectionTimeout") = 15
    Application("SurveyDatabase_CommandTimeout") = 30
    Application("SurveyDatabase_CursorLocation") = 3
    Application("SurveyDatabase_RuntimeUserName") = ""
    Application("SurveyDatabase_RuntimePassword") = ""
    '--Project Data Connection
    Application("DealerSurveyDatabase_ConnectionString") = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=URL=fpdb/DealerSurvey.mdb"
    FrontPage_UrlVars(4) = "DealerSurveyDatabase_ConnectionString"
    Application("DealerSurveyDatabase_ConnectionTimeout") = 15
    Application("DealerSurveyDatabase_CommandTimeout") = 30
    Application("DealerSurveyDatabase_CursorLocation") = 3
    Application("DealerSurveyDatabase_RuntimeUserName") = ""
    Application("DealerSurveyDatabase_RuntimePassword") = ""
    '--Project Data Connection
    Application("WebSiteSurvey_ConnectionString") = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=URL=fpdb/WebSiteSurvey.mdb"
    FrontPage_UrlVars(5) = "WebSiteSurvey_ConnectionString"
    Application("WebSiteSurvey_ConnectionTimeout") = 15
    Application("WebSiteSurvey_CommandTimeout") = 30
    Application("WebSiteSurvey_CursorLocation") = 3
    Application("WebSiteSurvey_RuntimeUserName") = ""
    Application("WebSiteSurvey_RuntimePassword") = ""
    '--
    Application("FrontPage_UrlVars") = FrontPage_UrlVars
    '==FrontPage Generated - endspan==
    End Sub
    </SCRIPT>
    <head><title>Web Site Settings for Active Server Pages</title><html xmlns:mso="urn:schemas-microsoft-com:eek:ffice:eek:ffice" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882">
    <!--[if gte mso 9]><xml>
    <mso:CustomDocumentProperties>
    <mso:connectionstatus msdt:dt="string">new_page_1=2 cat_order=2 Database1=1 SurveyDatabase=2 DealerSurveyDatabase=1 WebSiteSurvey=1</mso:connectionstatus>
    </mso:CustomDocumentProperties>
    </xml><![endif]-->
    </head>

    Please help.
     
    mlungisi, May 20, 2010 IP
  2. RachelCole

    RachelCole Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This is a pretty common problem in ASP.NET.
    I almost lost some clients over this one.

    Make sure in IIS you're Application Pool isn't set to recycle.
    If it recycles on a periodic basis, it'll knock the session out.
     
    RachelCole, May 21, 2010 IP
  3. mlungisi

    mlungisi Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks RachelCole, so far things are better. I haven't been kicked out with my testing account and I believe this might the solution, however I need to run some tests with customers.
     
    mlungisi, May 24, 2010 IP