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/