Pages

Search This Blog

Saturday 21 June 2014

Logout test...

Hi friends, I think you are practising and creating a web application using my tips and with help of “Google”.

If you say “Yes” I had almost done it. Then I want to test your application. Cool I won’t ask to send your web application to me ..... ;) I just say something to try in your application.

Just press “Logout” (See session class) button in your application. You may think “what?? That’s it ?? what you have tested in my application??” .

Wait .... Wait .... Now press back arrow in your keyboard. Then see what happens in your application.

“Yes” that’s it....

Today I will say “what has to be done in our project after pressing logout button so that it never navigates back page again”.

Normally, we will create a session and assign user value while user login in to the application and then we will make session value into “Null” or we will “expire” session.

Normally in logic we will write “if session value equal to null goes to home page”.

protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Username"] != null)
        {

    Label.Text = "Welcome" + " " + Session["Username"].ToString();
        }

        else
        {
       
        Label.Text = "expired";

       Response.Redirect("./home.aspx");

        }
    }

I too write the same logic but sometimes to make session value null it takes some “millsec”. If session has expired also if we press back arrow button it navigates to before page in our application.

So here I had a solution to overcome this problem.... J We will disable the functionality in the browser. We will do this by writing a code in “javascript” in “head” tag.

<script type = "text/javascript" >
    function changeHashOnLoad() {
        window.location.href += "#";
        setTimeout("changeHashAgain()", "50");
    }

    function changeHashAgain() {
        window.location.href += "1";
    }

    var storedHash = window.location.hash;
    window.setInterval(function () {
        if (window.location.hash != storedHash) {
            window.location.hash = storedHash;
        }
    }, 50);

</script>


We will call the “changeHashOnLoad” function in body.

<body onload="changeHashOnLoad();">


Simple now your application is perfect. 

                                                               -Your's Santoshklpkl

No comments:

Post a Comment

Animated Social Gadget - Blogger And Wordpress Tips Twitter Bird Gadget