Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2012-03-19
6
Medium Priority
?
787 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 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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
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

CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

722 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