Solved

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

Posted on 2012-03-19
6
750 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
Comment Utility
0
 
LVL 1

Assisted Solution

by:imranrizvi
imranrizvi earned 125 total points
Comment Utility
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
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 20

Assisted Solution

by:BuggyCoder
BuggyCoder earned 125 total points
Comment Utility
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
Comment Utility
any luck?
0
 

Author Closing Comment

by:niceguy971
Comment Utility
Thanks
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
LINQ question 7 20
Need to Modify a Script I found 5 75
Limiting string to two deciamls 18 30
How to open a link from vb.net app 3 8
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now