如何收集有关 ASP.NET MVC 中应用程序使用情况的统计信息?
我想收集统计信息,例如页面浏览量、每个用户的评论数等。我考虑过使用观察者模式。 我如何在 ASP.NET MVC 中实现这个?
I'd like to collect statistical information, such as PageViews, Number of comments for each user, etc. I've thought about using the observer pattern. How would I implement this in ASP.NET MVC?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于无法通过直接查询数据库来收集信息的情况,我会考虑通过过滤器属性来实现。 开发一个自定义过滤器来收集您需要的信息并将其存档。 使用过滤器装饰您希望过滤器收集信息的操作。 请参阅此 MSDN 页面,了解如何创建自定义操作筛选器。
For the cases where you can't collect the information via a direct query against the database, I would think about implementing this via filter attributes. Develop a custom filter that collects the information that you need and archives it. Decorate the actions that you want the filter to collect information on with the filter. See this MSDN page on how to create a custom action filter.
最近我发现
DDD 事件 和 这个cntext中使用的ThreadStatic属性,你觉得怎么样?
recently I discover
DDD events and ThreadStatic attribute used in this cntext, what do you think?
观察者模式并不适合这里。 您描述的功能应该使用您的应用程序使用的任何模型来捕获。 例如,如果您想跟踪每个用户的评论数量,那么这意味着您可能有一个评论数据库表。 您可以简单地编写一个 SQL 查询,为您提供用户列表以及他们在该表中创建的评论的计数。
就像是
The observer pattern doesn't really fit here. The functionality you describe should be captured using whatever model your application is using. So for example, if you want to track number of comments for each user, then that means you likely have a comments database table. You can simply write a SQL query that gives you a list of users and a count of the comments they have created in that table.
something like