Achieve "record the User Logon Time and exit time, record the user IP address at the same time, and record the province and city addresses corresponding to the user IP Address"

Source: Internet
Author: User

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/

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.