Implementation "Record user logon time and exit time, while recording user IP, and to record the user IP corresponding province and City address"

Source: Internet
Author: User
Tags httpcontext

Want to achieve "record user logon time and exit time, while recording user IP, and to record the user IP corresponding province and City address"

With Session_Start and session_end, implementation is the original idea, the result is not ideal.

The main time is not accurate, can not set the timeout time too short.

Key process:

Create a new 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 is spywin.aspx code

The following is the code for 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 critical (not all) steps above, add code < SCRIPT language = "JavaScript" to the real site master page >
function Launch_spywin ()
{
Spywin = open (' spywin.aspx ', ' Spywin ',
' Width=100,height=100,left=2000,top=0,status=0 ');
Spywin.blur ();
}
OnUnload = Launch_spywin;



</script>

In order to record the logon time and so on, need to add in the logged in event

Common.loglogin (Textboxlog.text);

Login page Plus: code < Asp:textbox runat = "server" ID = "Textboxlog" CssClass = "Textboxlog element-hide" ></Asp:tex Tbox >
</form >
</Body >
<%--//2010-4-8 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.