Learn MVC Using Angular Idle

This article demonstrates MVC using Angular Idle with a UI Bootstrap. This article will show you how to get your application to report if a user is idle.

Angular Idle

Angular Idle can use an Angular module to detect and respond to idle users. We can almost maintain the session on the client side.

Follow the steps given below and we can use an Angular Idle in AngularJS in MVC.

  • Create MVC project.
  • Configure Angular Idle.
  • Work with Angular Idle.

Create an MVC Project

Open Visual Studio 2015.

Go to New menu >Click New and then Project. Now, it will open a New Project Window.

You can select ASP.NET Web Application on Framework 4.6. Enter the name of the project in the Solution name text box, then click OK.

One more Window should appear. Select the MVC template in this popup and click Ok. Now, you can start.

Configure Angular Idle

We will download the idle plugin from the following sources:

Open the _Layout.cshtml and refer the.js file from downloaded folder to this view page:

Angular Module

You will need to include the module as a dependency of your application.

Angular Config

You should also set your options, using the KeepaliveProvider, IdleProvider in your Angular config file.

Angular Controller

You can set what action will be performed on the user idle times. With the below code, I will be shown a warning message and be notified of the session logout.

Angular Run

After configuring the angular.idle.js, you must initiate the function in your Angular Run function.


Set your HTML with the warning dialog and timeout dialog that is given below.

This code should configure your main Angular Controller and where we need to go to show this idle screen.

Angular Route

Run the Application. Now it will appear browser & see the result

Output 1

You need to refer to the login controller for login username and password.

Output 2

After the Login Manager, the home page will appear, as shown below.

Output 3

Stay idle for 5 seconds. Now, click or touch the screen to reset your idle state.

Output 4

Over your idle minutes, it will ask you to Logout.

Output 5

Suppose a user is busy with some other tab in the browser. You can set an idle countdown and sessions expiration information will load on top of the browser tab.

In this article, we have taken a look at MVC using Angular Idle. If you have any queries, please tell me in the comments section. Your comments are very valuable.

I'm a Dotnet Developer & Blogger. And also I'm working as a senior software engineer. I would like to spend my precious time writing articles, research on .Net technologies, and learning new technologies.
Exit mobile version