Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 458
  • Last Modified:

javascript - capture user inactivity

We have an ASP.Net/ VB.Net web application. If the user is inactive for 5 minutes(no keystroke or mouse movement) then the user should be asked for a password again to continue using the application.

I think I can do it through javascript using a timer, but how can I have this javascript function be called from each aspx page? I think its not a good idea to copy and paste the javascript function on each aspx page. Is there a global place where I can place the javascript code & call it from each aspx page?

Please advise. Thanks in advance.
0
vdesai_8
Asked:
vdesai_8
1 Solution
 
basicinstinctCommented:
1. put the javascript in an empty text file
2. save it as whatever.js on your webserver
3. include it on each page like this:
<script type="text/javascript" src="whatever.js"></script>
0
 
RejojohnyCommented:
>> If the user is inactive for 5 minutes(no keystroke or mouse movement) then the user should be asked for a password again to continue using the application.

A better solution would be to set the session timeout of your application as 5 minutes in your web.config

<configuration>
 <system.web>
    <sessionState mode="InProc" cookieless="false" timeout="5" />
.....

and your code in global.asax must check whether there is a active session and if not, redirect him to the page which will ask for the password ..

but if you have to use javascript and you want it be used in all the pages, then use a master page and every aspx page must have this page as the "master" file .. then you need to have the script  statement mentioned above ONLY in one page and that is the master page ...
<script type="text/javascript" src="whatever.js"></script>

this will save the effort of copying the script tag in all your aspx pages ..

Rejo
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now