跟踪每个请求游客信息 [英] track visitor info on every request

查看:199
本文介绍了跟踪每个请求游客信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Asp.net的WebForms我想追踪访问者的信息就像谷歌Analytics(分析)一样。当然,我可以使用谷歌分析这一目的,但我想知道我怎么能做到同样的事情Asp.net 3.5和SQL Server 2008。

Using Asp.net webforms I want to track down visitor info just like Google Analytics does. Of course, I can use Google Analytic for this purpose but I want to know how can I achieve the same thing with Asp.net 3.5 and SQL Server 2008.

我要存储的IP,国家,游客的URL引荐,分辨率除了上回发每个页面请求。我期待50K +访问的每一天。

主要关心的是我想要做的方式,它不应该阻止当前的请求。

Main concern is I want to do it in a way that it should not block current request.

即一般来说,当我们到数据库保存数据情况,当前请求停止对特定的SP打电话说明书,当它执行完SP或TSQL语句向前推进。我想跟进插入和忘记的做法。它应该在后台插入当我通过参数特定事件或功能。

i.e In general it happens when we save data in to db, current request stops on particular SP calling statment and moves ahead when it finishes executing SP or tsql statement. I want to follow "Insert and Forget" approach. It should insert in background when I pass parameter to particular event or function.

我发现下面这个方案:

1. PageAsynchTask

2. <一个href=\"http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.beginexecutenonquery.aspx\"相对=nofollow> BeginExecuteNonQuery

3. jQuery的Post方法和WebService(但我不相信这个,不知道我应该怎么去了解吧)

I found below alternatives for this :
1. PageAsynchTask
2. BeginExecuteNonQuery
3. Jquery Post method and Webservice (But I am not confident about this, and wondering how should I go about it)

我希望我已经提到正确我的问题。

I hope I've mentioned my problem properly.

任何人能告诉我,哪一个更好的方法吗?也让我知道,如果你不是列出了一个任何其他的想法或更好的办法。您的帮助将是非常美联社preciated。

Can anybody tell me which one is better approach? Also let me know if you've any other ideas or better approach than the listed one. Your help will be really appreciated.

推荐答案

在服务器端的后台线程问题是每一个要求是要占用两个线程。一个服务于ASP.NET请求,一个用于记录要记录的内容。所以,你最终由于ASP.NET线程耗尽其可扩展性问题。和日志数据库中的每一个请求是一个很大的不,不。

Problems with any background thread in server side is each and every request is going to occupy two threads. One for serving the ASP.NET request and one for logging the stuff you want to log. So, you end up having scalability issues due to exhaustion of ASP.NET threads. And logging each and every request in database is a big no no.

最好是只写使用一些高性能的日志库日志文件。记录库高度为多线程优化的日志记录。他们不产生I / O对每一个来电信息。日志存储在存储缓冲器和定期刷新。您应该使用EntLib或log4net的日志记录。

Best is to just write to log files using some high performance logging library. Logging libraries are highly optimized for multi-threaded logging. They don't produce I/O calls on each and every call. Logs are stored in a memory buffer and flushed periodically. You should use EntLib or Log4net for logging.

您可以使用拦截每一个GET,POST一个HttpModule,然后将里面的HttpModule可以检查Request.Url是一个aspx与否。然后,你可以阅读Request.Headers [__ ASYNCPOST],看看它是否是真,这意味着它是一个UpdatePanel异步更新。如果所有这些条件都为真,您只需登录请求到存储在日志文件

You can use an HttpModule that intercepts each and every GET, POST and then inside the HttpModule you can check whether the Request.Url is an aspx or not. Then you can read Request.Headers["__ASYNCPOST"] and see if it's "true", which means it's an UpdatePanel async update. If all these conditions are true, you just log the request into a log file that stores the

您可以从客户端IP:

HttpContext.Current.Request.UserHostAddress; 
or 
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

要拿到机器的IP地址,而不是代理使用以下code

To get the IP address of the machine and not the proxy use the following code

HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

但是你不能得到国家。您将有记录IP在日志文件,然后再处理使用一些控制台应用程序或作业,这将解决知识产权的国家的日志文件。你需要得到一些IP->国家数据库来完成这项工作。我已经使用 http://www.maxmind.com/app/geoip_country之前

有关的屏幕尺寸,你将不得不依靠一些JavaScript。这对发现在cookie中客户端和存储的屏幕大小在每一页上使用JavaScript。

For screen size, you will have to rely on some javascript. Use a javascript on each page that finds the size of the screen on the client side and stores in a cookie.

var screenW = 640, screenH = 480;
if (parseInt(navigator.appVersion)>3) {
 screenW = screen.width;
 screenH = screen.height;
}
else if (navigator.appName == "Netscape" 
    && parseInt(navigator.appVersion)==3
    && navigator.javaEnabled()
   ) 
{
 var jToolkit = java.awt.Toolkit.getDefaultToolkit();
 var jScreenSize = jToolkit.getScreenSize();
 screenW = jScreenSize.width;
 screenH = jScreenSize.height;
}

一旦你把它存储在cookie(我还没有证明code),您可以通过使用Request.Cookies时读取来自HTTP模块的屏幕大小,然后在日志文件中记录它。

Once you store it in a cookie (I haven't shown that code), you can read the screen dimensions from the HttpModule by using Request.Cookies and then log it in the log file.

所以,这给你的登录IP,屏幕尺寸,从IP查找全国各地,并从记录过滤的UpdatePanel异步回发的解决方案。

So, this gives you solution for logging IP, screensize, finding country from IP, and filtering UpdatePanel async postback from logging.

这是否给你解决问题的完整的解决方案?

Does this give you a complete solution to the problem?

这篇关于跟踪每个请求游客信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆