Prblem Working with Session

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vkas
    New Member
    • Feb 2009
    • 78

    Prblem Working with Session

    hi Fellows

    i had a logout link !!
    when the User click!
    i used session.clear() through this i clear all the session objects
    and then the page is being reponse .redirected to the default page!!

    session becomes clear !
    works ok until u Click back!
    but if u click back button it goes back !!!
    i dont want to happen this

    how could it stopped
  • PRR
    Recognized Expert Contributor
    • Dec 2007
    • 750

    #2
    You need to check on each page whether user is authenticated or not ...and on logout redirect the user to login page or some other page accessible to all...
    Code:
    if (User.Identity.IsAuthenticated)
            {
                //go on
            }
            else
            {
                //clear session 
                // Redirect to login page
            }
    In case you are using generic identity you need to set the current thread principal ..

    Comment

    • Vkas
      New Member
      • Feb 2009
      • 78

      #3
      hi Deep

      I am checking it works ok

      Un Authorize user is being checked in each page using a id!


      but after the user clicks the logout
      this is the code !
      Session.Clear()
      Response.Redire ct("Default.asp x")

      if i try to access the page throug address bar the page is responded to the default page ! as the user had been logged out and id is being cleared from the session
      but

      if i clicked back the user again become log in !!

      Comment

      • Vkas
        New Member
        • Feb 2009
        • 78

        #4
        where iz every one yar !


        i havent tesse any of you so much

        Comment

        • alamodgal
          New Member
          • Dec 2008
          • 38

          #5
          hiiiiiiiiiiiii
          You can use this script code in <head> tag of your pages

          <script>
          history.forward ();
          </script>

          this will not save your previous history and your back button doesn't show previous page of yours!

          Comment

          • kunal pawar
            Contributor
            • Oct 2007
            • 297

            #6
            use session.abandan t();

            which dispose all session values. Please do not use session.clear() ;

            Comment

            • Vkas
              New Member
              • Feb 2009
              • 78

              #7
              what is the difference Between Both
              Can u tell me ! Kunal

              Comment

              • kunal pawar
                Contributor
                • Oct 2007
                • 297

                #8
                I am expecting question.

                Session.Abandon :
                1) Cancels the current Session.
                2) It destoys session from memory.

                Session.Clear
                1) clears all values from Session state
                2) Session Variables are present with blank or null value.

                Comment

                • Vkas
                  New Member
                  • Feb 2009
                  • 78

                  #9
                  ok thank you

                  after i done session .abundant ()
                  i redirect my page to my Home page !

                  but when the user clicks on back button it again goes in page yet i have made a check that if the session value becomes empty then user should be redirected to the Home page ! any idea how can i stop the user to go back when he is log out

                  Comment

                  • kunal pawar
                    Contributor
                    • Oct 2007
                    • 297

                    #10
                    From log out page do not redirect to home page
                    create intermediat page, onload of that page it redirectes to home page

                    for eg. As user click on log out

                    session.Abandon ();
                    Response.Redire ct("ClearHistor y.aspx")

                    In ClearHistory.as px

                    using javascript in body tag

                    onload="windows .location='Defa ult.aspx';"

                    So when click on logout it redirect to clearHistory and this page alway redirect to Default.aspx so user can not go back

                    Comment

                    • PRR
                      Recognized Expert Contributor
                      • Dec 2007
                      • 750

                      #11
                      have you enabled anonymous login? or denied anonymous users?
                      also
                      Code:
                      FormsAuthentication.SignOut();

                      Comment

                      • Vkas
                        New Member
                        • Feb 2009
                        • 78

                        #12
                        y i have done that the method that Kunal said worked in my practice site

                        but i think this method is not a very gud technique i will now make anew login page then would try to Use yours Method

                        Comment

                        • Frinavale
                          Recognized Expert Expert
                          • Oct 2006
                          • 9749

                          #13
                          Just so you know, when you click the "back" button in the Web Browser a cached version of your page is shown.

                          This means that there is no call made to the web server....it is simply showing the person the content of the page that was cached by the browser.

                          Look into using <meta> tags to tell the web browser not to cache the content...such as:
                          Code:
                          <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE, must-revalidate, max-age=0">
                          <meta http-equiv="expires" content="0">
                          <meta http-equiv="Pragma" content="no-cache">
                          From experience, I've found that meta tags don't always work...but if you research this you will have a much better idea of what needs to be done to prevent the cached page from being displayed when the back button is clicked.

                          Comment

                          • Vkas
                            New Member
                            • Feb 2009
                            • 78

                            #14
                            ok Frinavale!

                            I will research on the thing that you have told me !

                            and then will try to impliment them in my Site ! thanks again!

                            If i couldnt then Will get help from all of the Experience people here!

                            Comment

                            Working...