locked
Multi device user session RRS feed

  • Question

  • User-749058405 posted

    I have developed a web application with a custom forms login. I am experimenting now with storing the session in SQL. What I am interested in doing is allow the user to persist the login like Facebook does and it be device specific. So each device has its own session and the user can go to a page and see all connected sessions, disconnect them, etc.. I am not sure how to implement this though and separate the different devices. I am assuming it is stored in a cookie with some device specific code that links them. Has anyone else worked this out already or have any ideas?

    Monday, December 22, 2014 9:44 PM

Answers

  • User1104055534 posted

     Please try to use the code below to get the mac address.

     [DllImport("Iphlpapi.dll")]  

    02       private static extern int SendARP(Int32 dest,Int32 host,ref Int64 mac,ref Int32 length);  

    03       [DllImport("Ws2_32.dll")] 

    04       private static extern Int32 inet_addr(string ip); 

    05   

    06       private void Page_Load(object sender, System.EventArgs e) 

    07       { 

    08            try

    09            { 

    10                 string userip=Request.UserHostAddress; 

    11                 string strClientIP = Request.UserHostAddress.ToString().Trim(); 

    12                 Int32 ldest = inet_addr(strClientIP); //destination ip  

    13                 Int64 macinfo = new Int64();  

    14                 Int32 len = 6;  

    15                 int res = SendARP(ldest,0, ref macinfo, ref len); 

    16                 string mac_src=macinfo.ToString("X"); 

    17                 if(mac_src == "0") 

    18                 { 

    19                     if (userip == "127.0.0.1") 

    20                     { 

    21                         Response.Write("Localhost!"); 

    22                     } 

    23                     else

    24                     { 

    25                         Response.Write("welcome" + userip + "<br>"); 

    26                     } 

    27                      return; 

    28                 } 

    29   

    30                 while(mac_src.Length<12) 

    31                 { 

    32                     mac_src = mac_src.Insert(0,"0"); 

    33                 } 

    34   

    35                 string mac_dest=""; 

    36   

    37                 for(int i=0;i<11;i++) 

    38                 { 

    39                      if (0 == (i % 2)) 

    40                      { 

    41                           if ( i == 10 ) 

    42                           { 

    43                                 mac_dest = mac_dest.Insert(0,mac_src.Substring(i,2)); 

    44                           } 

    45                           else

    46                           { 

    47                                 mac_dest ="-" + mac_dest.Insert(0,mac_src.Substring(i,2)); 

    48                           } 

    49                      }  

    50                 } 

    51   

    52                 Response.Write ("welcome "+userip+ "<br>" + ",MAC address"+mac_dest

    53   

    54                  +   "<br>"); 

    55            } 

    56            catch(Exception err)  

    57            {  

    58                 Response.Write(err.Message); 

    59            } 

    60       }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 25, 2014 9:35 PM