You must Sign In to post a response.
  • Category: ASP.NET

    Logout should end session

    The forum thread has not been reviewed by Editors yet. Readers are advised to use their best judgement before accessing this thread.
    This thread will be reviewed shortly.
    If you think this thread contain inappropriate content, please report to webmaster.
    Hi,

    I want to logout using asp.net with C#. When i logout it goes to log in page but when i press back button then it display main (previous) page. How can i stop this.Please provide me code.I use Session.Abandon() but only this does not work.

    Thanks
    Nitin
  • #31879
    The back button has no click event associated with it in the Javascript DOM.


    If you wanted to get from page1.htm to page2.htm without the user being able to get back to page1.htm, you could add the following to
    page1.htm:


    <a href="#"
    onclick="location.replace('page2.htm');return false">Go to page 2 with no way to get back</a>


    Now when they click the link, they get to page2.htm, if they click the browser's back button, it takes them to the page they were on
    BEFORE page1.htm

    or try this

    Response.Cache.SetCacheability(HttpCacheability.NoCache)


    or
    try this logic

    try putting a members name in top of the web form using session and if he logs off , empty that session string.. and validate every page that if that string is empty redirect to loginpage

    reply which one worked

  • #31880
    add the following code in each and every page load event

    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Cache.SetAllowResponseInBrowserHistory(false);

    or

    add the following code in logout page


    Response.Write("<script language=javascript>var wnd=window.open('','newWin','height=1,width=1,left=900,top=700,status=no,toolbar=no,menubar=no,scrollbars=no,maximize=false,resizable=1');</script>");
    Response.Write("<script language=javascript>wnd.close();</script>");
    Response.Write("<script language=javascript>window.open('Login.aspx','_parent',replace=true);</script>");

  • #31896
    Hi Rama Krishna,

    When i press button twice then it open sign out page. It is not working properly.
    First click on back it display web page expire but again clicking back button it display previous page.
    Thanks
    Please try again.

  • #31898
    hi Nitin Agarwal

    which method you are using?
    put the code in out side of the postback

  • #31932
    Hi Rama Krishna,

    I simply put code in page_load out side of Postback.

    private void Page_Load(object sender, System.EventArgs e)
    {

    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Cache.SetAllowResponseInBrowserHistory(false);


    }
    I also put this page_load code in login page.

    private void Button1_Click(object sender, System.EventArgs e)
    {

    Response.Write("<script language=javascript>var wnd=window.open('','newWin','height=1,width=1,left=900,top=700,status=no,toolbar=no,menubar=no,scrollbars=no,maximize=false,resizable=1');</script>");
    Response.Write("<script language=javascript>wnd.close();</script>");
    Response.Write("<script language=javascript>window.open('Login.aspx','_parent',replace=true);</script>");
    Session.Abandon();


    }
    But after clicking back button twice it shows previous page. Please Try again.
    Also see my drag drop problem of dragging listbox items from one to another using javascript.

    What is ur yahoo ID. I want to chat with U. My yahoo ID : nitin_agarwal5@yahoo.com

    Thanks a lot
    Nitin

  • #31940
    put the foloowing code in Logout page not in login page, its working fine, if you are using this method no need to use the first method. create one login page and one logout page and other pages, in the log out page put the following code, then you can underdtand whats the logic is than you can implement in your applicitaion.


    Private Sub btnLogut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Response.Write("<script language=javascript>var wnd=window.open('','newWin','height=1,width=1,left=900,top=700,status=no,toolbar=no,menubar=no,scrollbars=no,maximize=false,resizable=1');</script>")
    Response.Write("<script language=javascript>wnd.close();</script>")
    Response.Write("<script language=javascript>window.open('Login.aspx','_parent',replace=true);</script>")
    Session.Abandon()

    End Sub

  • #91197
    Hi all,
    I suggest to use
    FormsAuthentication.SignOut();

    try it also in VB if you are using it.

  • #142940
    Hi Ramakrishna, very useful content, i modified your code a litle..

    regrats from mexico....

  • #145878
    use Response.Cache.SetAllowResponseInBrowserHistory(false) in page_load event of every page and check

  • #152137
    Try this :
    private void Page_Load(object sender, System.EventArgs e)
    {

    Session.Abandon();

    FormsAuthentication.SignOut();

    Response.Redirect("index.aspx");

    }

    Thanks
    Shankar V

  • #154729
    Hi to all

    I used Ramakrishna's code.
    It works fine.

    i want to add one more facility. It is...

    After logout if any one clicks BACK button, i want to display a messge saying "some text".
    what line of code should be added to ur code.

    reply quick.

  • #340840
    Session: Its nothing but defined as a period of time shared between the web application and user. Every user has individual session. Items/Objects can be placed into the Session which would only define these object for that user. Session contains key variables which help to identify the related values. This can be thought of as a hash table. Each user would represent a different key node in the hash identifying unique values. The Session variables will be clear by the application which can clear it, as well as through the timeout property in the web config file. Usually the timeout is 20 minutes by default.



    Session Variables are stored on the server, can hold any type of data including references, they are similar to global variables in a windows application and use HTTP cookies to store a key with which to locate user's session variables.



    The collection of session variables is indexed by the name of the variable or by an integer index. Session variables are created by referring to the session variable by name. You do not have to declare a session variable or explicitly add it to the collection.



    Lets get it cleared from following example:



    Session["firstName"] = "Gaurav" //User's first name

    Session["lastName"] = "Arora" //User's last name



    // Clear the session variable

    Session["FirstName"] = null;



    //Clear all Session variables

    Session.Abandon();





    Note:

    By default, ASP.NET session state is enabled for all ASP.NET applications.

    Thanks & regards,
    Gaurav Kumar Arora
    Site Coordinator - DNS
    My blog - http://gaurav-arora.com


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.