0

I have asp.net website. When I create a test page with a Thread.Sleep before page load. There is forms authentication for login. After one hour of wait the page automatically logs out. So I want to see what is the reason for this logout. I am planning to capture all the HttpConnection Communications using C# code. I want to see the communication close reason only. I am running the website in local machine using Visual Studio 2005.

Can you please share code for achieving this functionality?

Note: I understand this can be achieved using tools like tcpDump. But currently I am trying to develop a code for this functionality alone – to see the reason of connection close/logout.

UPDATE:

I have the following code. But how do I achieve my task - how to find the reason for all connection close/logout. Please help me since I am totally new to socket programming.

 protected void Page_Load(object sender, EventArgs e)
{

    IPHostEntry host;
    string localIPAddress = "?";
    host = Dns.GetHostEntry(Dns.GetHostName());
    foreach (IPAddress ip in host.AddressList)
    {
        if (ip.AddressFamily == AddressFamily.InterNetwork)
        {
            localIPAddress = ip.ToString();
        }
    }

    System.Net.Sockets.Socket mySocket = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Raw, System.Net.Sockets.ProtocolType.IP);
    mySocket.Bind(new System.Net.IPEndPoint(System.Net.IPAddress.Parse(localIPAddress), 0));
    mySocket.SetSocketOption(System.Net.Sockets.SocketOptionLevel.IP, System.Net.Sockets.SocketOptionName.HeaderIncluded, 1);

    byte[] inBytes = new byte[] { 1, 0, 0, 0 };
    byte[] outBytes = new byte[] { 0, 0, 0, 0 };
    mySocket.IOControl(System.Net.Sockets.IOControlCode.ReceiveAll, inBytes, outBytes);
}
LCJ
  • 22,196
  • 67
  • 260
  • 418
  • Why that question mark `string localIPAddress = "?";`? – Pratik Deoghare Jun 23 '11 at 12:57
  • Try surrounding your code with `try{}catch{}`. See if there are any exceptions being thrown. – Pratik Deoghare Jun 23 '11 at 13:22
  • There is no exception. I am looking for code that will tell how to find start and close time for all connection, connection logout time, connection logout/close/expire reason etc..Please help – LCJ Jun 23 '11 at 13:26

1 Answers1

1

I think you are looking in the wrong place... With forms authentication, the logout occurs because the authentication cookie expires. If you look at the System.Web.Security.FormsAuthentication.SignOut() method with .Net Reflector you can see that it signs you out by giving you a new cookie that expires in the past.

David
  • 34,223
  • 3
  • 62
  • 80
  • Is there a way to extend this default SignOut time and make the cookie not to expire? – LCJ Jun 27 '11 at 05:18
  • Yes, are you using the FormsAuthenticaton.RedirectFromLogon method in your login code? If so, the 2nd argument lets you make the cookie never expire. If you are manually setting the cookie, then you can handle the expiration yourself. – David Jun 27 '11 at 13:52
  • We are NOT using RedirectFromLoginPage. We are using FormsAuthentication.SetAuthCookie(SessionManager.UserID.Value.ToString(), false); Response.Redirect(appUrl[1] + "&BackUrl=BackCall"); What changes should I make to the above code to work equivalentyly (only difference being cookie expiration time) ? – LCJ Jun 27 '11 at 16:40