locked
session Not expires when user close browser? RRS feed

  • Question

  • hi..

    i am using session in y silverlight web application.
    i used chrome and mozilla browser . here after login into the application i created a session and now i closed the browser window and again open the browser window the type the url means it automatically loggedin to the user page.

    so i need to to avoid the auotmatic login after my browser window is closed.
    so during my browser window close how to kill the session?

    need ur suggestions with examples..

    Note: 
    i create the session using my wcf service
    regards

    gopal.s
    • Edited by gopal_krish Wednesday, November 28, 2012 10:45 AM
    Wednesday, November 28, 2012 10:42 AM

Answers

  • You can do it using java script, In asp.net we can call javascript function on body "onunload" - <body onunload="RemoveSession()">

    Not sure how can be done in silverlight.

     function RemoveSession()
        {       
             if ( g_isPostBack == true )
             {
                //g_isPostBack = false;
                return;
             }    
              var webUrl = 'LogOffPage.aspx';
              var queryString = '?LogoffDatabase=Y';
              var returnCode = callAjax(webUrl, queryString);
        }
        
         function callAjax(webUrl, queryString)
        {
             var xmlHttpObject = null;
             try
             {
                  if (window.xmlhttpRequest)
                  {
                  // Firefox, Opera 8.0+, Safari...      
                    xmlHttpObject = new XMLHttpRequest();
                  }
                  else if (window.ActiveXObject) 
                  { 
                    try 
                    { 
                    xmlHttpObject = new ActiveXObject('Msxml2.XMLHTTP');
                    } 
                    catch (e)
                    { 
                        try
                        { 
                        xmlHttpObject = new ActiveXObject('Microsoft.XMLHTTP');
                        } 
                        catch(ex)
                        {  
                             if ( xmlHttpObject == null )
                             {
                                  window.alert('AJAX is not available in this browser');
                                  return 'No Browser'; 
                             }
                        }
                    }
                  }
             }
             catch(ex)
             {              
                 
             }         

            try
            {        
                xmlHttpObject.open("POST", webUrl + queryString, true);             
                xmlHttpObject.onreadystatechange = function() 
                { 
                if (xmlHttpObject.readyState == 4) 
                { 
                 //alert(xmlHttpObject.responseText); 
                } 
                } 
                xmlHttpObject.send(null);              
            }
            catch(ex)
            {  
                alert('Error:' + ex.message);
            }        
         
         return xmlHttpObject.responseText;     
        } 


    Harpal Singh



    • Edited by Harpalsgh Wednesday, November 28, 2012 4:47 PM
    • Marked as answer by LeoTang Thursday, December 6, 2012 9:34 AM
    Wednesday, November 28, 2012 4:45 PM