开发者

C# Program for Analyzing Http Connection

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 follow开发者_开发知识库ing 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);
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜