Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Web-application--C#.Net-- the window { "Your session has expired."  } .

Posted on 2012-03-19
6
Medium Priority
?
802 Views
Last Modified: 2012-04-25
Please provide an example showing how to create pop-up window (web-application is written in C#. Net 4.0). The web-application should display this window { "Your session has expired."  }to the user when the session has expired.  Session_End event from global.asax CANNOT BE used.

Thanks
0
Comment
Question by:niceguy971
6 Comments
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 500 total points
ID: 37740877
0
 
LVL 1

Assisted Solution

by:imranrizvi
imranrizvi earned 500 total points
ID: 37740933
There is no way to open a popup automatically on session expire or any other event fire.

if user explicitly expires the session then you can show the popup.

If it auto expires you cannot do anything as it is a different thread where global.asax events get called.
0
 
LVL 16

Accepted Solution

by:
Rose Babu earned 500 total points
ID: 37741037
There is an easy JS process i can suggest to you. and i used in my .NET projects as well.

instead of checking asp session time, you can count the js time to predict the session timeout. once the page is inactive for a timeperiod then the session get cleared.
so we can count the time till then throw an alert to the user.

use the countdown.js file given in the below sample and modify the alert process http://www.javascriptsource.com/time-date/countdown-timer.html

and you can use the modified below countdown.js in your pages
// countdown.js
var mins
var secs;

function cd() {
    mins = 1 * m("30"); // change minutes here (Your asp session timeout)
    secs = 0 + s(":01"); // change seconds here (always add an additional second to your total)
    redo();
}

function m(obj) {
    for (var i = 0; i < obj.length; i++) {
        if (obj.substring(i, i + 1) == ":")
            break;
    }
    return (obj.substring(0, i));
}

function s(obj) {
    for (var i = 0; i < obj.length; i++) {
        if (obj.substring(i, i + 1) == ":")
            break;
    }
    return (obj.substring(i + 1, obj.length));
}

function dis(mins, secs) {
    var disp;
    if (mins <= 9) {
        disp = " 0";
    } else {
        disp = " ";
    }
    disp += mins + ":";
    if (secs <= 9) {
        disp += "0" + secs;
    } else {
        disp += secs;
    }
    return (disp);
}

function redo() {
    secs--;
    if (secs == -1) {
        secs = 59;
        mins--;
    }

    //document.getElementById("CountDownDiv").value = dis(mins,secs); // displays the cowntdown time if needed in your page

    if ((mins == 2) && (secs == 0)) {
        window.alert("Your session is going to expire in 2 minutes. "); // alert the user before session got expired
    }
    else if ((mins == 0) && (secs == 0)) {
        window.alert("Your session got expired. "); // change timeout message as required
        // window.location = "yourpage.htm" // redirects to specified page once timer ends and ok button is pressed
    } else {
        cd = setTimeout("redo()", 1000);
    }
}

function init() {
    cd();
}
window.onload = init;

Open in new window

add the below line in your page(s) head. you can use it in master page also.
<script type="text/javascript" src="countDown.js"></script>

Open in new window

It is working very well in my project.
Give a try. Hope you will like this.
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 20

Assisted Solution

by:BuggyCoder
BuggyCoder earned 500 total points
ID: 37741038
Here is a not so fancy solution:-

On Button Click or using SetTimeOut Javascript method, make an ajax call to server.

In The method on server, access the session in a try catch block.
if you get "object reference not set to an instance of object" exception, send the repsonse back to the UI as error

Read the repsonse and show an alert saying "Session Expired".

Take the user to login page.
0
 
LVL 16

Expert Comment

by:Rose Babu
ID: 37756809
any luck?
0
 

Author Closing Comment

by:niceguy971
ID: 37895659
Thanks
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question