How can I prevent the user from going to the previous page?

I have an ASP.NET MVC application with three views: view1, view2, view3. The logical way to navigate the user through them: view1view2view3.

When the user reaches view3, I have to prevent them from loading view2, even using the back button in my browser.

What is a good, browser-independent way to implement this?

+3
source share
6 answers

In most applications, you need to deal with the ability to return from the browser. The user is used to it, and he wants to use it, and he more or less hates pages that try to trick them when they return and go.

Do not try to trick you, what do you think he wants to do, and then try to execute a page that is not completely broken.

+4
source

Add the referrer page check for page loading in your application, and then show the page or redirect the user back to the view in use. You cannot manipulate or prohibit basic navigation on the client, but you can solve this problem on the server side

+2
source

, , , , , ( ).

:

1) . , , , , , . , "" view1. 2 , .

2) , , - , . ( ).

a) . , view2:

if (request.urlreferrer.absolutepath == "controllerview1")
{ //good }
else
{ //bad }

, "" , . , , view2.

, , , ( request.urlrefferer null). ( , .) :

b) - . 1/2/3 , . db, . , view 2 - :

if (dbrow.last_saved_page_num == 1)
{ // good }
else
{ // bad
  redirect("view" + dbrow.last_saved_page_num + 1);
}
+1

javascript ( , ). , .

0

JavaScript, .

0

view1 view 2, , jquery, :

$(document).ready(function(){ window.history.forward(); });

<html onload="window.history.forward()">

, , , , , , , .

0

Source: https://habr.com/ru/post/1711774/


All Articles