Tracking User Activity

本文介绍如何在ASP.NET应用程序中记录已登录用户的活动,并将这些数据保存到数据库中。通过详细记录用户行为,如页面访问和操作执行,可以提供比传统网站统计数据更深入的分析。此外,还展示了如何展示特定用户的活动历史。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://dotnetslackers.com/articles/aspnet/Tracking-User-Activity.aspx

 

Scott Mitchell talks about tracking user activity in web applications.

hide]

Introduction

I like data. I go gaga over measurable metrics. Nothing makes me happier than storing information and then seeing it expressed in tables of numbers and colorful charts. Whenever I work on a web application I am always looking for interesting data to record and analyze, and the most interesting (and potentially profitable) data that every website owner should track are usage statistics. Web server log files and online tools like Google Analytics provide an array of useful metrics, including how many unique visitors accessed your site, what pages were the most popular, what days of the week and hours of the day represent peak demand, and so forth.

Many ASP.NET web applications support user accounts, enabling visitors to create an account and sign in to the site. With a little bit of effort you can track the activity of your logged on users. This can include recording activities such as what pages were visited as well as what actions were performed. Consider a page that allows a user to manage his profile. When first arriving at this page the activity log might add an entry like "Visiting the User Profile page." After updating his e-mail address, the activity log might record, "Changed e-mail address from scott@example.com to mitchell@example.com." Such usage tracking offers a deeper level of analysis than is possible with log files or online visitor statistic tools. Instead of data that report total number of visitors or how the average user is interacting with the site, user activity tracking can provide a very detailed view of how a particular individual is using the application and what actions he is performing while signed on to the site.

This article examines how to record your users' activities in a database table and display this information in a web page. A complete, working demo application that shows these techniques in action is available for download.

ASP.NET's Membership system makes it easy to create and manage user accounts. Many websites that use Membership are configured to use SqlMembershipProvider, a Membership provider that ships with the .NET Framework and stores user account information in a Microsoft SQL Server database. The demo application for this article uses SqlMembershipProvider, storing user account information along with the user activity log in a Microsoft SQL Server 2008 Express Edition database file (ASPNETDB.mdf), which you will find in the application's App_Data folder. For more information on using the Membership system refer to my ASP.NET Web Security tutorial series.

 

转载于:https://www.cnblogs.com/yangfada/archive/2009/01/07/1371386.html

根据你的代码,我理解您想要在删除Rokedispatchordermanagement模型的记录之前,检查approval_can_run_id值是否等于“删除”,如果是,则不允许删除。但是,您的代码中有几个错误。 首先,您需要将“unlink”方法的重写代码放在“Rokedispatchordermanagement”模型中,而不是在“approval.flow”模型中。 其次,您应该在每个记录上检查approval_can_run_id的值,而不是在“approval.flow”模型上进行操作。您可以使用“self”关键字来引用当前记录。 最后,您需要使用“in”运算符来检查approval_can_run_id是否包含“删除”值,而不是使用“==”运算符来比较。 下面是更正后的代码: ``` class Rokedispatchordermanagement(models.Model): _name = 'roke.dispatch.order.management' _inherit = ['mail.thread', 'mail.activity.mixin'] _description = "派船单" _rec_name = "code" client = fields.Many2one('roke.partner', string='客户', tracking=True, required=True) department_manager = fields.Many2one('res.users', string='创建人', tracking=True, default=lambda self: self.env.user.id) box_number = fields.Char(string='箱号') shipping_companies = fields.Char(string='船公司') field_station = fields.Char(string='场站') ship_name_voyage = fields.Char(string='船名航次') port_of_discharge = fields.Char(string='卸货港') box_type = fields.Many2one('roke.box.type', string='箱型') code = fields.Char(string='单据编号', track_visibility='onchange') def unlink(self): for record in self: if '删除' in record.approval_can_run_id.mapped('name'): raise UserError("不能删除") return super(Rokedispatchordermanagement, self).unlink() ``` 这个更正后的代码应该可以达到您想要的效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值