Results 1 to 3 of 3

Thread: Automatic Log Out

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2001
    Location
    Alberton, Gauteng, South-Africa
    Posts
    48

    Question Automatic Log Out

    Howzit!!

    I am maintaining a Web page where the User needs to be logged in I then lock that user account so that only one account can be used at a time, Now if the User forgets to logg out or leaves the system un attented for a set amount of time I would like to Logg him out automatically and redirect the user to a page, I had a go at it and here's my code, could you please help me out??

    ********************
    <OBJECT RUNAT=Server SCOPE=Session ID=MyInfo PROGID="MSWC.MyInfo"></OBJECT>
    <SCRIPT LANGUAGE=VBScript RUNAT=Server>
    Sub Session_OnStart
    If isEmpty(Application("counter")) Then
    Application("counter") = 0
    Application("count") = 0
    else
    Application("counter") = Application("counter") + 1
    Application("count") = Application("count") + 1
    end If

    Session.TimeOut=5

    End Sub

    Sub Session_onEnd

    Application("count") = Application("count") - 1

    dim cnMain
    dim lcDate
    dim lcTime
    dim sSQL

    lcdate = FormatDateTime(Now(),vbShortDate)
    sday = mid(lcdate,instr(lcdate,"/")+1,instr(mid(lcdate,instr(lcdate,"/")+1),"/")-1)
    if len(sday) < 2 then
    sday = "0" & sday
    end if
    smonth = mid(lcdate,1,instr(lcdate,"/")-1)
    if len(smonth) < 2 then
    smonth = "0" & smonth
    end if
    syear = "20" & right(lcdate,2)
    lcdate = sday & "/" & smonth & "/" & syear

    lcTime = FormatDateTime(Now, vbLongTime)

    sSQL = "Provider=SQLOLEDB.1;Persist Security Info=False;Data Source=MyServer;Initial Catalog=MyCat;User ID=Guest;Password=;ConnectionTimeout=10;"

    Set cnMain = Server.CreateObject("ADODB.Connection")
    cnMain.Mode = abModeReadWrite
    cnMain.ConnectionString = sSQL
    cnMain.open

    sTime = FormatDateTime(time,vbShortTime)
    conn.Execute("INSERT INTO AuditTrail (Audit_UID, Audit_Date, Audit_Time, Audit_Flag, Audit_InOut, Audit_Reason) Values ('" & Session("sUID") & "','" & lcdate & "','" & lctime & "','0','In','Session Time Out')")

    conn.Execute("Update Users Set User_Locked = 0 WHERE User_UID = '" & Session("sUID") & "' AND User_Comp_UID = '" & Session("sCID") & "'")


    cnMain.Close

    Response.Redirect "http://www.newsclip.co.za/asp/session.asp"

    End Sub
    </Script>

    ********************

    Thanks in Advance!
    ;-)
    Jaco
    South-Africa

  2. #2
    chenko
    Guest
    So whats the problem? I dont think you can redirect users using the global.asa thou :/

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    you are right, you cant response anything in a global.asa chenko.

    Besides resonse.redirect in a Session_ONEnd makes absolutly no sense at all.

    plus. Your code appears that it should work besides the response.redirect, but also take note, Session onEnd will NOT fire off until the Session expires, not when they leave the page or close their browser
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

Posting Permissions

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



Click Here to Expand Forum to Full Width