I have an MVC Web Api application running in vs2012, As the user requirment application should redirect to locked screen when application is idle for 30 second.Can anyone please guide me to solve this issue.
-
A simple (albeit not secure) solution would be to have a timer in JavaScript running that redirects the page after 30 seconds of inactivity. – germi May 28 '15 at 07:57
2 Answers
Web API cannot provoke redirects.
What you need to do is something on the client side (JavaScript) that detects the lack of activity during 30 seconds and then locks the screen, for example placing a CSS overlay. If you really want to redirect to a locked page, for example the login page, you need to change the browser url, like this: window.location.href = newUrl;
. You should also terminate the user session at this point. If not, someone can write another URL of your application, and will be redirected to it with the authentication in the current session.
What you can do to enter the locked state is to use JavaScript's setTimeout
. Set a timeout of 30 seconds with a callback to the locking script. And do something to reset the time out if you detect activity on the page, which usually involves subscribing to events.
The most difficult to implement is the dectection of activity in the page. You can see some ideas on this SO Q&A: Detecting idle time in JavaScript elegantly. See the highly voted answers, which include very interesting ideas.
The easest way in my opinoin to write this <meta http-equiv="refresh" content="30;URL='home.html'" />
in the header of your page
and set session time out in web.xml or web config to be equal 30

- 854
- 1
- 8
- 18
-
I think @Girish is saying he wants to redirect if no response is returned within 30 seconds. This will always redirect. – Neil Thompson May 28 '15 at 08:10
-
In this case i think he need to configure the response time out in server config file. – Bashar Abutarieh May 28 '15 at 08:12