Click here to Skip to main content
15,881,882 members
Articles / Web Development / ASP.NET
Tip/Trick

Custom Session Warning (Jquery)/ Normal JavaScript Session Alert Pop up in MVC 4 Application with Form Authentication Sliding Expiration -Part I

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
8 Feb 2014CPOL2 min read 17.6K   9   1
This part just talks of Custom Jquery UI Pop up.

Introduction

This is my first article, so please let me know in case you find something missing or amiss. Feel free to give your suggestions as well as criticisms. I am just another .NET developer next door who enjoys doing his work.

While recently working on an MVC application, I was asked to give a session warning pop up. Initially, I Googled a lot and thought that it could be very easily implemented with JavaScript. Although I could find some references that talked about giving a pop up warning in JavaScript or jquery when the session was about to expire, none could completely solve the issues that I was facing. So I decided to write a tip which any developer can easily use for future reference.

Background

Some of the links that I found useful are listed below:

Using the Code

If you will look into the first link that is shared, you will get a session.warning.zip.You can directly download this file from here. This file became my starting point and I thought that I closed the requirement very easily.

(http://www.cypressnorth.com/downloads/session.warning.zip) I have also copy pasted the code that I got from this file for reference. You just need to include this file in Layout page that is shared so that all the views can easily reference this file. Download the file from the given location. There are four things that are of our interest and the fifth one we are ignoring as of now:

  1. sess_pollInterval - Time you want the page to keep polling and execute the sessInterval function
  2. sess_expirationMinutes - Your application session expiration time
  3. sess_warningMinutes - After what duration you want the pop up to show
  4. Log Off URL link - Set the Log off URL here
  5. Some Ajax function - Which we will look at later on

The first change that was asked by client was to give a Custom POP up instead of JavaScript alert with 2 options as "Continue" and "Log Out".

Now this was achieved easily Jquery UI Alert:
Ref attachment for changes in the sessInterval method

I have also kept the old code for reference and in case you want to override the default CSS of jquery UI, then you just need to add the CSS class name to dialogclass as it's commented there.

Uncomment it and add your class name.

Points of Interest

I hope you enjoyed this tip. In the next part(Part II), I will talk about the new issue that I faced.

Form Authentication timeouts -even when the user has clicked on "Keep Looking" and Ajax methods returning UnAuthorized call failure.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionLooking for the second part Pin
Member 1115037620-Oct-14 15:14
Member 1115037620-Oct-14 15:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.