在ASP.NET MVC 3和剃须刀观点用户跟踪 [英] User tracking with ASP.NET MVC 3 and razor views

查看:175
本文介绍了在ASP.NET MVC 3和剃须刀观点用户跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是在ASP.NET MVC 3使用剃刀的看法时,实现整个网站的用户跟踪的最佳方式。

What's the best way to implement user tracking throughout your web site when using Razor views in ASP.NET MVC 3.

在网络表单我把一些code在母版使用cookie并登录我的网站上每个URL,一个人在访问一个数据库,但我不知道在哪里实现这个code在ASP.NET MVC。

In webforms I'd put some code in the masterpage to use a cookie and log each url on my site that a person visits in a database, but I'm not sure where to implement this code in ASP.NET MVC.

推荐答案

我想做到这一点的最好办法是建立一个全球行动筛选,并跟踪访问那里。

I guess the best way to do this is to create a Global Action Filter, and track visits there.

创建一个动作过滤器属性:

Create an action filter attribute:

public class UserTrackingActionFilterAttribute : ActionFilterAttribute
{
    public override void OnResultExecuting(ResultExecutingContext context)
    {
        base.OnResultExecuting(context);

        //save url, userId from session, etc...
    }
}

其注册为全球ASAX一个全球性的过滤器:

Register it as a global filter in global asax:

protected void Application_Start()
{      
    // Register global filter
    GlobalFilters.Filters.Add(new UserTrackingActionFilterAttribute());

    RegisterGlobalFilters(GlobalFilters.Filters);
}

这就是全部。尼斯?

That's all. Nice?

这篇关于在ASP.NET MVC 3和剃须刀观点用户跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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