Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Session End

Session End

Scheduled Pinned Locked Moved ASP.NET
helpquestionannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vuthaianh
    wrote on last edited by
    #1

    I've got a problem: When user enter a webpage or login that means a Session for that user created and when user close IE browser or log out of web page or something like that that means Session Ended In file Global.asax.cs and in Session_End event i wrote a segment of code to log out users automatically when users turn off the IE browser but it haven't worked. I want to ask: Session_End event raises before of after the real session ends ? I think it raise before the real session ends but if it happens so my segment of code must have worked protected void Session_End(Object sender, EventArgs e) { SqlConnection con = new SqlConnection(ThongTin.CONNECTIONSTRING); SqlCommand command = new SqlCommand(); command.Connection = con; command.CommandText = "UPDATE HOCVIEN SET Online = 0 WHERE MaHocVien = @MaHocVien"; command.Parameters.Add("@MaHocVien",SqlDbType.Char,10); command.Parameters["@MaHocVien"].Value = Session["MaHocVien"].ToString(); try { con.Open(); command.ExecuteNonQuery(); } catch(Exception ex) { Response.Write(ex.Message); Response.Write(ex.StackTrace); } finally { con.Close(); command.Dispose(); } } Thanks in advance

    P 1 Reply Last reply
    0
    • V vuthaianh

      I've got a problem: When user enter a webpage or login that means a Session for that user created and when user close IE browser or log out of web page or something like that that means Session Ended In file Global.asax.cs and in Session_End event i wrote a segment of code to log out users automatically when users turn off the IE browser but it haven't worked. I want to ask: Session_End event raises before of after the real session ends ? I think it raise before the real session ends but if it happens so my segment of code must have worked protected void Session_End(Object sender, EventArgs e) { SqlConnection con = new SqlConnection(ThongTin.CONNECTIONSTRING); SqlCommand command = new SqlCommand(); command.Connection = con; command.CommandText = "UPDATE HOCVIEN SET Online = 0 WHERE MaHocVien = @MaHocVien"; command.Parameters.Add("@MaHocVien",SqlDbType.Char,10); command.Parameters["@MaHocVien"].Value = Session["MaHocVien"].ToString(); try { con.Open(); command.ExecuteNonQuery(); } catch(Exception ex) { Response.Write(ex.Message); Response.Write(ex.StackTrace); } finally { con.Close(); command.Dispose(); } } Thanks in advance

      P Offline
      P Offline
      Plunging_Falcon
      wrote on last edited by
      #2

      The problem with SessionEnd is that it doesn't occur when you close the browser, but the session ends which can be 20 minutes after you close the browser or more (depends on your web.config). Anyway, it will happen it just takes time.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups