Solved

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

Posted on 2012-03-19
6
755 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 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Signal R -send data to client: only if they are allowed to see it ? 1 50
asp day pilot 3 18
tableview is not updating 1 7
Linq asp.net mvc 13 6
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

786 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