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. General Programming
  3. C#
  4. Session.clear ans session.abandon

Session.clear ans session.abandon

Scheduled Pinned Locked Moved C#
17 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.
  • S Offline
    S Offline
    Sonia Gupta
    wrote on last edited by
    #1

    i know the meaning now i implemented it in the project using the following code protected void Page_Load(object sender, EventArgs e) { Session["Sonia"] = "11"; Session["Sonia1"] = "12"; Session.Abandon(); foreach (string ste in Session.Keys) { Response.Write(ste + ":" + Session[ste]); } } initially i used the two session variables. if i use the session.clear() it leave me with 0 session count but the session vaiables remain the same if using the sesssion.abandon()

    Sonia Gupta Soniagupta1@yahoo.co.in Yahoo messengerId-soniagupta1 Love is Friendship and Friendship is Love....

    P G 2 Replies Last reply
    0
    • S Sonia Gupta

      i know the meaning now i implemented it in the project using the following code protected void Page_Load(object sender, EventArgs e) { Session["Sonia"] = "11"; Session["Sonia1"] = "12"; Session.Abandon(); foreach (string ste in Session.Keys) { Response.Write(ste + ":" + Session[ste]); } } initially i used the two session variables. if i use the session.clear() it leave me with 0 session count but the session vaiables remain the same if using the sesssion.abandon()

      Sonia Gupta Soniagupta1@yahoo.co.in Yahoo messengerId-soniagupta1 Love is Friendship and Friendship is Love....

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Session.Abandon lets you access the session variables until the page goes out of scope (e.g. you redirect the user to another page). Session.Clear removes the variables instantly.

      Deja View - the feeling that you've seen this post before.

      1 Reply Last reply
      0
      • S Sonia Gupta

        i know the meaning now i implemented it in the project using the following code protected void Page_Load(object sender, EventArgs e) { Session["Sonia"] = "11"; Session["Sonia1"] = "12"; Session.Abandon(); foreach (string ste in Session.Keys) { Response.Write(ste + ":" + Session[ste]); } } initially i used the two session variables. if i use the session.clear() it leave me with 0 session count but the session vaiables remain the same if using the sesssion.abandon()

        Sonia Gupta Soniagupta1@yahoo.co.in Yahoo messengerId-soniagupta1 Love is Friendship and Friendship is Love....

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

        Session.Abandon marks the Session object to be abandoned. When the current request is finished, the Session object will be removed, but it's available as long as the code is running. When the user makes another request, a new Session object will be created. Session.Clear only removes the session variables from the current Session object. The Session object itself will not be removed.

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

        S 1 Reply Last reply
        0
        • G Guffa

          Session.Abandon marks the Session object to be abandoned. When the current request is finished, the Session object will be removed, but it's available as long as the code is running. When the user makes another request, a new Session object will be created. Session.Clear only removes the session variables from the current Session object. The Session object itself will not be removed.

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

          S Offline
          S Offline
          Sonia Gupta
          wrote on last edited by
          #4

          i am using the following code Session["Sonia"] = "11"; Session["Sonia1"] = "12"; Session.Clear(); it renders the Session["Sonia"] and session["Sonia1"] to null. Session["Sonia"] = "11"; Session["Sonia1"] = "12"; Session.Abandon(); leaves the session["Sonia"] AND Session["Sonia"] AS IT IS. Is this what u mean to say.

          Sonia Gupta Soniagupta1@yahoo.co.in Yahoo messengerId-soniagupta1 Love is Friendship and Friendship is Love....

          P G 2 Replies Last reply
          0
          • S Sonia Gupta

            i am using the following code Session["Sonia"] = "11"; Session["Sonia1"] = "12"; Session.Clear(); it renders the Session["Sonia"] and session["Sonia1"] to null. Session["Sonia"] = "11"; Session["Sonia1"] = "12"; Session.Abandon(); leaves the session["Sonia"] AND Session["Sonia"] AS IT IS. Is this what u mean to say.

            Sonia Gupta Soniagupta1@yahoo.co.in Yahoo messengerId-soniagupta1 Love is Friendship and Friendship is Love....

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #5

            Sonia Gupta wrote:

            Session["Sonia"] = "11"; Session["Sonia1"] = "12"; Session.Abandon(); leaves the session["Sonia"] AND Session["Sonia"] AS IT IS. Is this what u mean to say.

            This is correct. Once you leave the scope of the request, Session["Sonia"] and Session["Sonia1"] will be removed, but until then you can still access these variables.

            Deja View - the feeling that you've seen this post before.

            S 1 Reply Last reply
            0
            • P Pete OHanlon

              Sonia Gupta wrote:

              Session["Sonia"] = "11"; Session["Sonia1"] = "12"; Session.Abandon(); leaves the session["Sonia"] AND Session["Sonia"] AS IT IS. Is this what u mean to say.

              This is correct. Once you leave the scope of the request, Session["Sonia"] and Session["Sonia1"] will be removed, but until then you can still access these variables.

              Deja View - the feeling that you've seen this post before.

              S Offline
              S Offline
              Sonia Gupta
              wrote on last edited by
              #6

              but the fucntion session.clear() clears the session values not the session key. here session.clear() clears the session key as well, y this is happening

              Sonia Gupta Soniagupta1@yahoo.co.in Yahoo messengerId-soniagupta1 Love is Friendship and Friendship is Love....

              G 1 Reply Last reply
              0
              • S Sonia Gupta

                i am using the following code Session["Sonia"] = "11"; Session["Sonia1"] = "12"; Session.Clear(); it renders the Session["Sonia"] and session["Sonia1"] to null. Session["Sonia"] = "11"; Session["Sonia1"] = "12"; Session.Abandon(); leaves the session["Sonia"] AND Session["Sonia"] AS IT IS. Is this what u mean to say.

                Sonia Gupta Soniagupta1@yahoo.co.in Yahoo messengerId-soniagupta1 Love is Friendship and Friendship is Love....

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

                Sonia Gupta wrote:

                i am using the following code Session["Sonia"] = "11"; Session["Sonia1"] = "12"; Session.Clear(); it renders the Session["Sonia"] and session["Sonia1"] to null.

                Actually, it removed the items. If it would just set the items to null, the Session.Count property would still return 2, but clearing the session items makes it return 0.

                Sonia Gupta wrote:

                Session["Sonia"] = "11"; Session["Sonia1"] = "12"; Session.Abandon(); leaves the session["Sonia"] AND Session["Sonia"] AS IT IS.

                Yes. The current session can't be removed until the current request is completed. That would be sawing off the branch you are sitting on.

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

                S 1 Reply Last reply
                0
                • S Sonia Gupta

                  but the fucntion session.clear() clears the session values not the session key. here session.clear() clears the session key as well, y this is happening

                  Sonia Gupta Soniagupta1@yahoo.co.in Yahoo messengerId-soniagupta1 Love is Friendship and Friendship is Love....

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

                  Sonia Gupta wrote:

                  but the fucntion session.clear() clears the session values not the session key.

                  No, it doesn't clear the values, it removes the items.

                  Sonia Gupta wrote:

                  here session.clear() clears the session key as well, y this is happening

                  The Session.Keys collection is a collection of the names in the Session.Items collection. As Session.Clear removes all the items in Session.Items, the Session.Keys collection also becomes empty.

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

                  S 1 Reply Last reply
                  0
                  • G Guffa

                    Sonia Gupta wrote:

                    i am using the following code Session["Sonia"] = "11"; Session["Sonia1"] = "12"; Session.Clear(); it renders the Session["Sonia"] and session["Sonia1"] to null.

                    Actually, it removed the items. If it would just set the items to null, the Session.Count property would still return 2, but clearing the session items makes it return 0.

                    Sonia Gupta wrote:

                    Session["Sonia"] = "11"; Session["Sonia1"] = "12"; Session.Abandon(); leaves the session["Sonia"] AND Session["Sonia"] AS IT IS.

                    Yes. The current session can't be removed until the current request is completed. That would be sawing off the branch you are sitting on.

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

                    S Offline
                    S Offline
                    Sonia Gupta
                    wrote on last edited by
                    #9

                    Guffa wrote:

                    can't be removed until the current request is completed

                    What's the meaning of this line. if u provide an example.

                    Sonia Gupta Soniagupta1@yahoo.co.in Yahoo messengerId-soniagupta1 Love is Friendship and Friendship is Love....

                    1 Reply Last reply
                    0
                    • G Guffa

                      Sonia Gupta wrote:

                      but the fucntion session.clear() clears the session values not the session key.

                      No, it doesn't clear the values, it removes the items.

                      Sonia Gupta wrote:

                      here session.clear() clears the session key as well, y this is happening

                      The Session.Keys collection is a collection of the names in the Session.Items collection. As Session.Clear removes all the items in Session.Items, the Session.Keys collection also becomes empty.

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

                      S Offline
                      S Offline
                      Sonia Gupta
                      wrote on last edited by
                      #10

                      one thing i wanted to make clarification about is that session.abandon() does not remove the key or the value until we navigate to another page.Once the use navigates to another page , both the key and the value gets removed. and as far as the removing of session key and value is concerned , session.clear() method is sufficient , according to my understanding . Then What's the need of session.abandon()?

                      Sonia Gupta Soniagupta1@yahoo.co.in Yahoo messengerId-soniagupta1 Love is Friendship and Friendship is Love....

                      P 1 Reply Last reply
                      0
                      • S Sonia Gupta

                        one thing i wanted to make clarification about is that session.abandon() does not remove the key or the value until we navigate to another page.Once the use navigates to another page , both the key and the value gets removed. and as far as the removing of session key and value is concerned , session.clear() method is sufficient , according to my understanding . Then What's the need of session.abandon()?

                        Sonia Gupta Soniagupta1@yahoo.co.in Yahoo messengerId-soniagupta1 Love is Friendship and Friendship is Love....

                        P Offline
                        P Offline
                        Pete OHanlon
                        wrote on last edited by
                        #11

                        Suppose that you want to continue working with the session in the context of the page, but you want the session to be cleared when you leave the page. If your page hosts another page in an iframe, then the inner page also has access to the session variable. This means that you can abandon the variable in the Page_Load, and still access it in the inner page.

                        Deja View - the feeling that you've seen this post before.

                        S 1 Reply Last reply
                        0
                        • P Pete OHanlon

                          Suppose that you want to continue working with the session in the context of the page, but you want the session to be cleared when you leave the page. If your page hosts another page in an iframe, then the inner page also has access to the session variable. This means that you can abandon the variable in the Page_Load, and still access it in the inner page.

                          Deja View - the feeling that you've seen this post before.

                          S Offline
                          S Offline
                          Sonia Gupta
                          wrote on last edited by
                          #12

                          session.abandon removes the key and the value. right?

                          Sonia Gupta Soniagupta1@yahoo.co.in Yahoo messengerId-soniagupta1 Love is Friendship and Friendship is Love....

                          P V G 3 Replies Last reply
                          0
                          • S Sonia Gupta

                            session.abandon removes the key and the value. right?

                            Sonia Gupta Soniagupta1@yahoo.co.in Yahoo messengerId-soniagupta1 Love is Friendship and Friendship is Love....

                            P Offline
                            P Offline
                            Pete OHanlon
                            wrote on last edited by
                            #13

                            Eventually yes.

                            Deja View - the feeling that you've seen this post before.

                            V 1 Reply Last reply
                            0
                            • P Pete OHanlon

                              Eventually yes.

                              Deja View - the feeling that you've seen this post before.

                              V Offline
                              V Offline
                              Virendrak
                              wrote on last edited by
                              #14

                              in, Session.Clear() Session key also remove. coz.. foreach (string ste in Session.Keys) { Response.Write(ste + ":" + Session[ste]); Response.Write("
                              "); } O/p is nothing.

                              Never Think That You Have Failed Instead Always Think That u hav Better Chance Next Time...

                              P 1 Reply Last reply
                              0
                              • S Sonia Gupta

                                session.abandon removes the key and the value. right?

                                Sonia Gupta Soniagupta1@yahoo.co.in Yahoo messengerId-soniagupta1 Love is Friendship and Friendship is Love....

                                V Offline
                                V Offline
                                Virendrak
                                wrote on last edited by
                                #15

                                in, Session.Clear() Session key also remove. coz.. foreach (string ste in Session.Keys) { Response.Write(ste + ":" + Session[ste]); Response.Write("
                                "); } O/p is nothing.

                                Never Think That You Have Failed Instead Always Think That u hav Better Chance Next Time...

                                1 Reply Last reply
                                0
                                • V Virendrak

                                  in, Session.Clear() Session key also remove. coz.. foreach (string ste in Session.Keys) { Response.Write(ste + ":" + Session[ste]); Response.Write("
                                  "); } O/p is nothing.

                                  Never Think That You Have Failed Instead Always Think That u hav Better Chance Next Time...

                                  P Offline
                                  P Offline
                                  Pete OHanlon
                                  wrote on last edited by
                                  #16

                                  What does this have to do with Session.Abandon removing the keys?

                                  Deja View - the feeling that you've seen this post before.

                                  1 Reply Last reply
                                  0
                                  • S Sonia Gupta

                                    session.abandon removes the key and the value. right?

                                    Sonia Gupta Soniagupta1@yahoo.co.in Yahoo messengerId-soniagupta1 Love is Friendship and Friendship is Love....

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

                                    Sonia Gupta wrote:

                                    session.abandon removes the key and the value. right?

                                    No, it doesn't. It marks the Session object for removal. When the request finishes, the entire Session object is removed. The items are never removed from the Session object.

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

                                    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