Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Session Management

Posted on 2007-07-28
3
Medium Priority
?
205 Views
Last Modified: 2012-06-21
How can i got message before session time out in asp.net 2.0(C#). I want to show a message box to user before session expire. Like "Your session going to expire, do you want to refresh?"
0
Comment
Question by:vikram_lashkari
2 Comments
 
LVL 2

Accepted Solution

by:
active_agent earned 200 total points
ID: 19584645
This function will generate a JS markup for the function based on the session time out set (10% of the time before the session timeout)

public static void RegisterSessionJS(System.Web.UI.Page oPage)
            {
                  //oPage.Session.Timeout = 1;
                  // 10% prior warning time
                  double sessionTimeOut = (oPage.Session.Timeout * 0.9) * 60000 ;
                  string sJS = "<SCRIPT Language=\"Javascript\">\n";
                  sJS += "window.setTimeout('SessionExpireWarning(" + sessionTimeOut + "," + (oPage.Session.Timeout * 60000) + ")'," + sessionTimeOut.ToString() + ");\n";
                  sJS += "</SCRIPT>\n";
                  if (!(oPage.ClientScript.IsStartupScriptRegistered("Session")))
                        oPage.ClientScript.RegisterStartupScript(oPage.GetType(),"Session",sJS );
            }

function SessionExpireWarning(nmSecs,ntotalmSecs){
      var endMS;
      var dtDate = new Date();
      var startMS = (((dtDate.getHours() * 60 * 60) + (dtDate.getMinutes() * 60) + dtDate.getSeconds()) * 1000) + dtDate.getMilliseconds();
                  if (window.confirm('Your session is about to expire. Do you wish to extend the Session?')){
                        dtDate = new Date();
                        endMS = (((dtDate.getHours() * 60 * 60) + (dtDate.getMinutes() * 60) + dtDate.getSeconds()) * 1000) + dtDate.getMilliseconds();
                        if ((endMS - startMS) >= (ntotalmSecs - nmSecs))
                        {
                              alert('Sorry your session is expired. we cannot extend it ');
                              window.location.reload();
                        }
                        else{
                              sVirtualDir = (sVirtual.length > 0? sVirtual:'');
                              window.showModalDialog('ExtendSession.aspx','','dialogHeight: 300px; dialogWidth: 400px;  edge: Raised; center: Yes; help: No; resizable: No; status: No; scroll=No');
                              window.setTimeout('SessionExpireWarning(' + nmSecs + ',' + ntotalmSecs + ')',nmSecs);
                        }
                  }
}

I hope this will help.




0
 
LVL 1

Expert Comment

by:Computer101
ID: 20475797
Forced accept.

Computer101
EE Admin
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

571 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