Solved

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

Posted on 2012-03-19
6
757 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 53

Assisted Solution

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

Assisted Solution

by:imranrizvi
imranrizvi earned 125 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 125 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Assisted Solution

by:BuggyCoder
BuggyCoder earned 125 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 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