C#的百度地图开发(六)用户访问网页的IP记录
2015-01-14 11:30
260 查看
在《C#的百度地图开发(五)IP定位》一文中,我们可以通过IP来定位,那这些IP要如何去获取呢?对于网站,我们可以能过用户访问页面时,记录其IP。因为用户访问页面时,是向服务器发起了请求,我们只要在服务器端作相应的处理,就可以记录了。如果使用Asp.Net开发站点,可以借助Global.asax(全局应用程序类)来记录。
(1).Application_PostAuthenticateRequest是页面访问发起验证请求时都会触发该函数,所以可以在此记录。
(2).记录IP信息,用户信息到数据库中,还可以进一步分析出某一时间段的在线用户。
得到了IP后,就可以按前面的来进行百度地图的定位了。
转载请注明出处http://blog.csdn.net/xxdddail/article/details/42707243。
public class Global : System.Web.HttpApplication { protected void Application_Start(object sender, EventArgs e) { } protected void Session_Start(object sender, EventArgs e) { } protected void Application_BeginRequest(object sender, EventArgs e) { } protected void Application_AuthenticateRequest(object sender, EventArgs e) { } protected void Application_Error(object sender, EventArgs e) { } protected void Session_End(object sender, EventArgs e) { } protected void Application_End(object sender, EventArgs e) { } protected void Application_PostAuthenticateRequest(object sender, EventArgs e) { // 提取窗体身份验证 cookie string cookieName = FormsAuthentication.FormsCookieName; HttpCookie authCookie = HttpContext.Current.Request.Cookies[cookieName]; if (null == authCookie) { // 没有身份验证 cookie。 return; } FormsAuthenticationTicket authTicket = null; authTicket = FormsAuthentication.Decrypt(authCookie.Value); if (null == authTicket) { // 无法解密 Cookie。 return; } string[] roles = authTicket.UserData.Split(new char[] { ',' }); FormsIdentity id = new FormsIdentity(authTicket); System.Security.Principal.GenericPrincipal principal = new System.Security.Principal.GenericPrincipal(id, roles); HttpContext.Current.User = principal; String visitIP = Request.UserHostAddress;//访问者的IP String visitUrl = Request.FilePath;//访问的页面(页面的JS、CSS也会获取,在记录时需要加以区分) } }注:
(1).Application_PostAuthenticateRequest是页面访问发起验证请求时都会触发该函数,所以可以在此记录。
(2).记录IP信息,用户信息到数据库中,还可以进一步分析出某一时间段的在线用户。
得到了IP后,就可以按前面的来进行百度地图的定位了。
转载请注明出处http://blog.csdn.net/xxdddail/article/details/42707243。
相关文章推荐
- 微信公众号开发访问第三方网页获取用户的openid
- C#微信公众号接口开发,灵活利用网页授权、带参数二维码、模板消息,提升用户体验之完成用户绑定个人微信及验证码获取
- C#微信公众号开发之网页授权oauth2.0获取用户基本信息(一)
- C#微信公众号开发-高级接口-之网页授权oauth2.0获取用户基本信息(二)
- C#微信公众号开发--网页授权(oauth2.0)获取用户基本信息一
- 如何在VS.NET/C# Builder开发的网页中也能实现DOS下录入数据回车换行的功能
- 在C#中访问AD用户信息的示例操作
- asp.net+C# 开发网页区域更新的方法
- 把 C# 语言开发的控件内嵌在网页里面
- php下用cookie统计用户访问网页次数的代码
- 使用C#开发用户控件
- Larbin 搜索引擎源码赏析——(五)为二次开发用户提供的进一步处理网页的接口函数
- 关于如何在C#程序中访问windows用户的密码:
- 单机版简易考试系统开发过程讲解(C#注册机、用户注册、考试系统、有偿提供全部源码)
- c# 实现网页上用户自动登陆|asp.net 模拟网站登录
- WinCE5.0移动平台开发笔记(c#中使用多线程访问winform中控件的若干问题(zt))
- 通过Cookie统计用户访问网页的次数
- C# 网页信息采集(数据访问)
- C# 访问AD中用户信息的几个操作
- Visual C# 2008+SQL Server 2005 数据库与网络开发--8.2.2 用户数据操作的并发