我有一个Asp。Net MVC 5网站。我想跟踪用户连续访问我的网站的天数。目前我有一个代码跟踪这在Login
行动,但我不能跟踪谁已经访问过的网站,并检查了"记住我"在登录页面的用户。不用说,我正在寻找一种方法来实现这一点,并尽可能减少性能损失。
try Like this,当你跟踪用户登录时,你可能会将用户的IP地址或用户名存储到数据库中。
您可以保存日期和时间以及IP和用户名。
从这个你可以跟踪访问过网站的用户
进入Models文件夹-> IdentityModels.cs
在ApplicationUser类中查找GenerateUserIdentityAsync方法。它被称为直接签名和cookie 1。
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
cookie调用从StartupAuth.cs类Startup -> ConfigureAuth -> app.UseCookieAuthentication -> Provider -> regenerateIdentity -> user。GenerateUserIdentityAsync
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)),
}
});