Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my project I want to implement this functionality:

When a user logs out from the website and then presses the back button he does not navigate to the previous page where he was when he logged out.

How do I do this?
Posted

Try this:
Just put this
javascript 
on the html section of aspx page above head section
XML
<script type = "text/javascript" >
function disableBackButton()
{
window.history.forward();
}
setTimeout("disableBackButton()", 0);
</script>

Refer more details: Disable Browser Back Button Using Javascript ASP.NET[^]
 
Share this answer
 
Have a read of this article,

Web Development - Disabling the back button[^]
 
Share this answer
 
Comments
Raje_ 12-Jul-12 4:18am    
Very useful link.
my +5.
Just go this link:-
How to disable browser's back button[^]

Best of luck.
 
Share this answer
 
Below article in CP defines the exactly the same functionality which you are looking for:
Disabling browser's back functionality on sign out from Asp.Net[^]
 
Share this answer
 
you just need to disable caching of the page by adding this code on page load.
C#
Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
Response.Cache.SetNoStore();
 
Share this answer
 
Comments
Member 8491154 12-Jul-12 6:04am    
on which page do I have to put this code? On the Login page?
graciax8 13-Jul-12 1:30am    
On the page where only logged in members are allowed to access. :)
The solution is applicable to almost every common broewser used.

Add the following script in the "<head></head>" tag.

HTML
<script type="text/javascript">
        window.history.forward();
        function disableBackButton() {
            window.history.forward();
        }
        setTimeout("disableBackButton()", 0);
    </script>


And call it in the body tag like this:

HTML
<body onload="disableBackButton();" onpageshow="if (event.persisted) disableBackButton();"  önunload="">
</body>
 
Share this answer
 
v3
Hi,

What i think, if you are providing login facility on your web. you must store user's credentials inside session.

now on logout trigger, abandon the session [Session.Abandon] and on every page of your site, at onLoad event, you need to check that

IF SESSION DOESNOT contain USER'S CREDENTIALS THEN
REDIRECT USER TO DEFAULT PAGE.
END IF
 
Share this answer
 
Comments
Member 8491154 12-Jul-12 8:18am    
I have already used this. But the page is not loaded when we press the back button

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900