To achieve "record the User Logon Time and exit time, record the user IP address, and record the province and city addresses corresponding to the user IP Address"
Using Session_Start and Session_End is the initial idea and the results are not satisfactory.
It is mainly because the time is not accurate and the TimeOut time cannot be set too short.
Key process:
Create An aspx page-spyWin. aspx
Code Protected void Page_Load (object sender, EventArgs e)
{
Common. LogOut ();
String script = "<script type = 'text/javascript '" +
"Language = 'javascript '>" +
"Function check_opener () {" +
"Parent. opener =''; "+
"Parent. close ();" +
"}" +
"Onload = function () {" +
"Self. blur ();" +
"SetTimeout ('check _ opener () ', 0);" +
"}" +
"</Script> ";
This. Controls. Add (new LiteralControl (script ));
}
// The above code is spyWin. aspx
// The following is the code of the Common class
Public static void LogLogin (string address)
{
MyBusiness. DbModel. LogForSale lfs = new LogForSale ();
Lfs. LoginTime = DateTime. Now;
Lfs. UserName = Credential. Name;
If (address. Length> 1)
{
Lfs. IP = address. Split (',') [0];
Lfs. Province = address. Split (',') [2];
Lfs. City = address. Split (',') [3];
}
Lfs. Save ();
System. Web. HttpContext. Current. Session ["LFS"] = lfs;
}
Public static void LogOut ()
{
If (Credential! = Null)
{
MyBusiness. DbModel. LogForSale lfs = System. Web. HttpContext. Current. Session ["LFS"] as MyBusiness. DbModel. LogForSale;
If (lfs! = Null & lfs. ID> 0)
{
Lfs. LogoutTime = DateTime. Now;
Lfs. Save ();
}
}
}
After completing the preceding (not all) steps, add
Code <Script language = "javascript">
Function launch_spyWin ()
{
SpyWin = open ('spywin. aspx ', 'splitwin ',
'Width = 100, height = 100, left = 2000, top = 0, status = 0 ');
SpyWin. blur ();
}
Onunload = launch_spyWin;
</Script>
To record the logon time, you must add
Common. LogLogin (TextBoxLog. Text );
Add:
Code <Asp: TextBox runat = "server" ID = "TextBoxLog" CssClass = "TextBoxLog Element-Hide"> </asp: TextBox>
</Form>
</Body>
<% -- // LogForSale -- %>
<Script type = "text/javascript" src = "http://fw.qq.com/ipaddress" charset = "gb2312"> </script>
<Script type = "text/javascript">
$ ('. Textboxlog'). val (IPData. join (',')));
</Script>
Http://anforen.5d6d.com/
Http://four-corner.appspot.com/