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. how to determine Session is Alive or not

how to determine Session is Alive or not

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nethelptutorialquestion
4 Posts 4 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.
  • B Offline
    B Offline
    Bajrang Singh
    wrote on last edited by
    #1

    Hi All. Iam new to asp.net. I want to know how can we determine that session is alive or expired. Actually I created a session Session["LoogeIn"] when user logs In, and I used this session across the application.But when saving or updating records , it gives Error if Session is expired ( I am using Session when savinf or updating records.) So I am confused how can I determine that whether Session is expired or not. And In case of Expire I want to redirect the page to login page, so session can start again. Thanks in advance. bye

    Bajrang Singh Using .net 2.0 (VS2005)

    G K 2 Replies Last reply
    0
    • B Bajrang Singh

      Hi All. Iam new to asp.net. I want to know how can we determine that session is alive or expired. Actually I created a session Session["LoogeIn"] when user logs In, and I used this session across the application.But when saving or updating records , it gives Error if Session is expired ( I am using Session when savinf or updating records.) So I am confused how can I determine that whether Session is expired or not. And In case of Expire I want to redirect the page to login page, so session can start again. Thanks in advance. bye

      Bajrang Singh Using .net 2.0 (VS2005)

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      If the session has expired, the user will get a new Session object, where the Items collection is empty. When you try to read a value from the empty collection you will get a null value, so you just have to check for that.

      --- single minded; short sighted; long gone;

      1 Reply Last reply
      0
      • B Bajrang Singh

        Hi All. Iam new to asp.net. I want to know how can we determine that session is alive or expired. Actually I created a session Session["LoogeIn"] when user logs In, and I used this session across the application.But when saving or updating records , it gives Error if Session is expired ( I am using Session when savinf or updating records.) So I am confused how can I determine that whether Session is expired or not. And In case of Expire I want to redirect the page to login page, so session can start again. Thanks in advance. bye

        Bajrang Singh Using .net 2.0 (VS2005)

        K Offline
        K Offline
        kapiljadhav
        wrote on last edited by
        #3

        Hey you have to check the sessions if they are empty during the page load event. write the below code on page load event If session("YOUR_SESSION_VARIABLE") = "" then response.redirect("LOGIN_PAGE_URL") End If Try this out..... Regards, Kaps

        H 1 Reply Last reply
        0
        • K kapiljadhav

          Hey you have to check the sessions if they are empty during the page load event. write the below code on page load event If session("YOUR_SESSION_VARIABLE") = "" then response.redirect("LOGIN_PAGE_URL") End If Try this out..... Regards, Kaps

          H Offline
          H Offline
          hammdo
          wrote on last edited by
          #4

          You can also use the global.asax and use the session time out method. With that you can redirect the user to a login page or a 'default' page for session timeout information. e.g., // this is inside the global.asax void Session_End(object sender, EventArgs e) { // 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 Server.Transfer("login.aspx"); } why Server.Transfer? here is more info on the do's and dont's http://www.developer.com/net/asp/article.php/3299641[^]

          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