Monday, 20 October 2014

ASP.NET Session Timeout


1. Create a webpage
KeepSessionAlive.aspx


2. Just add the below line in your master page (May be your Index Page), Inside <head> tag
<script language="javascript" type="text/javascript">
        var sessionTimeoutWarning = "<%= System.Configuration.ConfigurationSettings.AppSettings["SessionWarning"].ToString()%>";
        var sessionTimeout = "<%= Session.Timeout %>";
        var timeOnPageLoad = new Date();
        var sessionWarningTimer = null;
        var redirectToWelcomePageTimer = null;
        //For warning
        var sessionWarningTimer = setTimeout('SessionWarning()', parseInt(sessionTimeoutWarning) * 60 * 1000);
        //To redirect to the welcome page
        var redirectToWelcomePageTimer = setTimeout('RedirectToWelcomePage()',parseInt(sessionTimeout) * 60 * 1000);

        //Session Warning
        function SessionWarning() {
            //minutes left for expiry
            var minutesForExpiry =  (parseInt(sessionTimeout) - parseInt(sessionTimeoutWarning));
            var message = "Your session will expire in another " + minutesForExpiry + " mins. Do you want to extend the session?";

            //Confirm the user if he wants to extend the session
            answer = confirm(message);

            //if yes, extend the session.
            if(answer)
            {
                var img = new Image(1, 1);
                img.src = 'KeepSessionAlive.aspx?date=' + escape(new Date());

                //Clear the RedirectToWelcomePage method
                if (redirectToWelcomePageTimer != null) {
                    clearTimeout(redirectToWelcomePageTimer);
                }
                timeOnPageLoad =  new Date();
                sessionWarningTimer = setTimeout('SessionWarning()', parseInt(sessionTimeoutWarning) * 60 * 1000);
                //To redirect to the welcome page
                redirectToWelcomePageTimer = setTimeout('RedirectToWelcomePage()',parseInt(sessionTimeout) * 60 * 1000);
            }

            //*************************
            //Even after clicking ok(extending session) or cancel button, if the session time is over. Then exit the session.
            var currentTime = new Date();
            //time for expiry
            var timeForExpiry = timeOnPageLoad.setMinutes(timeOnPageLoad.getMinutes() + parseInt(sessionTimeout));

            //Current time is greater than the expiry time
            if(Date.parse(currentTime) > timeForExpiry)
            {
                alert("Session expired. You will be redirected to Logout page");
                window.location = "Logout.aspx";
            }
            //**************************
        }

        //Session timeout
        function RedirectToWelcomePage(){
            alert("Session expired. You will be redirected to Logout page");
            window.location = "Logout.aspx";
        }
    </script>

3. Add this in your web.Config under <appSettings>
<add key ="SessionWarning" value ="15"/>

4. Add this in your Web.Config under <system.web>
<authentication mode="Forms">
      <forms name="MyAuth" timeout="20" protection="All" loginUrl="index.aspx" slidingExpiration="true" />
    </authentication>

    <sessionState mode="InProc" cookieless="false" timeout="20" />

Monday, 16 June 2014

Tamil Days

Tamil Days:

1. பிரதம
2. துவிதிய
3. திரிதிய 
4. சதுர்த்தி 
5. பஞ்சமி 
6. சஷ்டி 
7. சப்தமி 
8. அஷ்டமி 
9. நவமி 
10. தசமி 
11. ஏகாதசி 
12. தூவாதசி 
13. திரியாதசி 
14. சதுர்தசி 
15. பௌர்ணமி / அமாவாசை