Sometimes we are in a situation that we don't want the user to visit the previous pages. This can be a scenario when the user logs out but uses the back button to navigate to the pages. In this article I will show you some simple ways you can use to prevent user from going back.
Using History(+1) Method:
Let's say that you have a page called Default.aspx which is the secure page and when you click the button you are redirected to another page Default2.aspx. Now from Default2.aspx. you don't want to go back to the Default.aspx.. You can achieve this easily using few lines of code.
Let's first catch the button click event and send the user to the Default2.aspx page.
|protected void Button1_Click(object sender, EventArgs e) |
Now if you press the button you will be redirected to the Default2.aspx page. If you press the back button you will be taken to the Default.aspx page. Now we will implement the functionality that will prevent the user to go to the Default2.aspx page.
In the Default.aspx html write the following code: