Hi all . I have tried different methods but i am still unable to disable my browsers back button. plz help me out. some of the methods that i have tried are -:

1)

on logout click i wrote this code in my .aspx.cs file

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
Response.Cache.SetNoStore();

2) Also i tried this java script function

<script type="text/javascript" language="javascript">
    function cancelBack()   
    {   
        if ((event.keyCode == 8 ||    
           (event.keyCode == 37 && event.altKey) ||    
           (event.keyCode == 39 && event.altKey))   
            &&    
           (event.srcElement.form == null || event.srcElement.isTextEdit == false)   
          )   
        {   
            event.cancelBubble = true;   
            event.returnValue = false;   
        }   

        if (window.event.keyCode == 13) 
        {
            event.returnValue=false; 
            event.cancel = true;
        }
    }   
    </script>

Don't disable the back button unless you have a really good reason. Seeing as you seem to be doing it on the logout page, you can achieve the same effect through session state. If session state says user is logged out (you update it when they do log out) when they go to a page that requires log in status, they get redirected to the login page.

All i wanted to do is don let the unauthorized user even see the admin section. When user logs out , session ends , but still someone can see the pages under admin section that the user visited, although he can't use it. Can u please suggest something by which i can clear the cache ???

By the way Thanks for the Answer.

Are you referring to seeing the pages in the browser history and cache or the ability to move backward through visited pages by pressing the back button? Sorry, I'm not sure exactly where the unauthorized user would see the pages.

When the authorized user logs out and then some anonymous user comes and clicks the back button , he can see the Functionality although he can't use it. I want to clear the cache. Doesn't that means it will disable the back button because now there is nothing in the cache to where it can refer...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.