I'm using default ASP.NET user controls and SQL user provider.
How can I log somewhere when users login to web and when logout ?
Is there some tricks for it or just write to some .log fi开发者_如何学JAVAle manually each time after user login. (Also , how can I check user IP adress ?)
Thank you.
The ASP.NET Login control has a LoggedIn event that you can add a handler for that does whatever you like, such as log it somewhere. Similarly, the LoginStatus control has a LoggedOut event.
The User IP address is available using the HttpContext: HttpContext.Current.Request.UserHostAddress; or HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
To log the logins you will need to handle the LoggedIn event and write to your log there. You can either manually set up a log or use an existing framework.
You have a few different options for getting the users IP:
Request.ServerVariables("REMOTE_ADDR");
Request.ServerVariables("HTTP_X_FORWARDED_FOR");
Request.UserHostAddress();
加载中,请稍侯......
精彩评论