問題描述
在 ASP.NET 站點上,有哪些技術可用于跟蹤在任何給定時間點登錄該站點的用戶數量?
On an ASP.NET site, what are some techniques that could be used to track how many users are logged in to the site at any given point in time?
例如,我可以生成一個報告,顯示如下內容:
So for example, I could produce a report showing something like this:
10:00am 11:00am 12:00pm 1:00pm 2:00pm ....
3/25 25 32 45 40 37
3/26 31 38 50 57 40
3/27 28 37 46 35 20
etc.
不,我們沒有使用 ASP.NET 成員資格提供程序,它使用基于本地/hacky 會話的方法來確定用戶是否處于登錄"狀態.
No, we're not using ASP.NET Membership provider, it uses a home-grown/hacky session based method of determining whether or not a user is in 'logged in' status.
推薦答案
網站是否讓用戶登錄?如果是這樣,那么您可以在每次請求新頁面時更新用戶表中的上次訪問"字段,然后每小時執行一次 SQL 查詢,獲取上次訪問中具有上次訪問"時間戳的每個人15 分鐘左右(假設當前在網站上).
Does the website log the user in? If it does, then you can update a "Last Visit" field in the user table every time they request a new page, and then every hour, just do a SQL query that grabs everybody who has a "Last Visit" timestamp within the last 15 minutes or so (assumed to currently be on the site).
如果您沒有人登錄,您可以通過 IP 地址而不是用戶名輕松登錄.但是,使用這種方法,您可能會遇到一些代理問題(即來自同一公司網絡的多個用戶可能都來自同一個 IP 地址,因此他們在您的總數中只算作一個用戶),但這應該是最小的.
If you're not having people log in, you could just as easily do it by IP address instead of username. With this method, though, you may run into some proxy issues (ie multiple users from the same corporate network may all come from a single IP address, so they only count as one user in your totals), but that should be minimal.
這篇關于確定 ASP.NET 站點的“活動"用戶數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!