我似乎无法找到原因或位置,但即使我将Membership.GetUser(userName,false)设置为false,LastActivityDate也始终更新,因此它不会更新LastActivityDate。我在任何其他访问GetUser的地方都没有任何其他代码。所以我在名为LastActivity的配置文件中创建了一个属性,但是我不明白为什么每次刷新页面时GetUser总是更新LastActivityDate。
private void SwitchMode(Mode mode)
{
ProfileCommon profile = Profile.GetProfile(UserName);
MembershipUser mu = Membership.GetUser(UserName, false);
bool isOnline = minutes(DateTime.Now - profile.LastActivity) >= Membership.UserIsOnlineTimeWindow ? false : true;
lblActivity.Text = mu.LastActivityDate.ToString();
switch (mode)
{
case global::Mode.Readonly:
profileAvatar.Visible = true;
profileDetails.Visible = true;
profileForm.Visible = false;
lblUserName.Text = UserName;
if (profile.Website != null)
{
lblWebsite.Visible = false;
lnkWebsite.Visible = true;
}
else
{
lblWebsite.Visible = true;
lnkWebsite.Visible = false;
}
lblSummary.Text = profile.Summary;
lnkWebsite.Text = profile.Website == string.Empty ? "-" : profile.Website;
lnkWebsite.NavigateUrl = profile.Website == string.Empty ? "-" : profile.Website;
lblLocation.Text = profile.Address.StateRegion + ", " + profile.Address.Country;
lblFullname.Text = profile.FirstName + " " + profile.LastName;
lblEmail.Text = profile.ShareEmail && mu != null ? mu.Email : "-";
lblGender.Text = profile.Gender == 0 ? "Male" : profile.Gender == 1 ? "Male" : "Female" ;
lblAge.Text = Convert.ToString(Math.Floor(DateTime.Today.Subtract(profile.BirthDate).TotalDays / 365.25));
lblMemberfor.Text = PrintTimeSpan1(DateTime.Now - mu.CreationDate);
lblVisited.Text = profile.Visits.ToString();
lblSeen.Text = PrintTimeSpan1(DateTime.Now - profile.LastActivity) + " ago";
lblProfileViews.Text = profile.Views.ToString();
if (HttpContext.Current.User.Identity.Name != UserName)
{
profile.Views += 1;
profile.Save();
}
if (isOnline)
{
lblStatus.Text = "online";
}
else
{
lblStatus.Text = "offline";
}
break;
case global::Mode.Edit:
profileAvatar.Visible = true;
profileDetails.Visible = false;
profileForm.Visible = true;
lblUserName.Text = UserName;
txtFirstName.Text = profile.FirstName;
txtLastName.Text = profile.LastName;
radioGender.SelectedIndex = profile.Gender;
ddlDay.SelectedValue = profile.BirthDate.Day.ToString();
ddlMonth.SelectedValue = profile.BirthDate.Month.ToString();
ddlYear.SelectedValue = profile.BirthDate.Year.ToString();
txtWebsite.Text = profile.Website;
ddlOccupation.SelectedValue = (profile.Occupation == string.Empty ? "0" : profile.Occupation);
txtStreet.Text = profile.Address.Street;
txtZipCode.Text = profile.Address.ZipCode;
txtStateRegion.Text = profile.Address.StateRegion;
ddlCountry.SelectedValue = (profile.Address.Country == string.Empty ? "0" : profile.Address.Country);
txtAvatar.Text = profile.Forum.AvatarUrl;
txtForumSignature.Text = profile.Forum.Signature;
chkNewsLetter.Checked = profile.NewsLetter;
chkShareEmail.Checked = profile.ShareEmail;
txtSummary.Text = profile.Summary;
break;
case global::Mode.Insert:
profileAvatar.Visible = false;
profileDetails.Visible = false;
profileForm.Visible = true;
break;
}
}
答案 0 :(得分:2)
您对Profile.GetProfile(UserName)的调用正在更新日期。我有同样的问题。在这里查看我的问题:Is it possible to access a profile without updating LastActivityDate?基本上,您必须修改获取配置文件详细信息的存储过程并删除一小段代码。
答案 1 :(得分:0)
如果您查看:http://msdn.microsoft.com/en-us/library/system.web.profile.profilebase.lastactivitydate.aspx,则表示在读取或修改配置文件时,上次活动日期会更新。在您的代码中,您“读取”配置文件(profile.Views + = 1),这可能是正在执行的操作,而不是对Membership.GetUser的调用。我自己没有对此进行测试,但希望它有所帮助...