【问题标题】:How to capture page views in MVC如何在 MVC 中捕获页面视图
【发布时间】:2015-06-26 20:56:31
【问题描述】:

在 MVC 中捕获页面查看次数和更新数据库的最佳方法是什么?我已经浏览了建议使用操作过滤器的what is the best way to capture page views per user in asp.net-mvc 解决方案。但是,如果我们想要跟踪传递给 action 方法的每个唯一参数的页面浏览量——比如 stackoverflow 如何计算每个问题的页面访问量?我认为,在这种情况下,我们不能使用操作过滤器,因为不同参数的页面浏览量会有所不同。

除了每次查看页面时增加数据库值之外,还有其他可用的解决方案吗?

【问题讨论】:

    标签: asp.net-mvc pageviews


    【解决方案1】:

    为什么不能使用动作过滤器

        public class MyActionFilter : ActionFilterAttribute
        {
            public override void OnActionExecuting(ActionExecutingContext filterContext)
            {
                var actionName = filterContext.ActionDescriptor.ActionName;
                var controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
                var parameterICareAbout = filterContext.ActionParameters["parameterICareAbout "];
                //write to database using parameterICareAbout
            }
         }
    

    至于不是每次都在数据库中存储值,您可以在您的应用程序中设置一个 Singleton 类来跟踪所有这些请求,然后以某种节奏将它们批量写入数据库/或在应用程序期间写入数据库降速过程

    【讨论】:

      猜你喜欢
      • 2015-11-11
      • 2010-11-07
      • 2011-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-06
      • 1970-01-01
      • 2015-01-24
      相关资源
      最近更新 更多