Membership.GetUser (username, isOnline) always updates LastActivityDate

I can't seem to find the reason or where, but LastActivityDate is always updated, even if I set Membership.GetUser (userName, false) to false so that it doesn't update LastActivityDate. I have no other code elsewhere that also accesses GetUser. So I created a property in the LastActivity profile, it works, but I don’t understand why GetUser always updates LastActivityDate every time I refresh the page.

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; } } 
+4
source share
2 answers

Your request in Profile.GetProfile (UserName) updates the date. I have the same problem. See My question here: Is it possible to access a profile without updating LastActivityDate? Basically, you will have to modify the stored procedure, which receives the profile data and removes a small block of code.

+2
source

If you look at: http://msdn.microsoft.com/en-us/library/system.web.profile.profilebase.lastactivitydate.aspx , it reports that the latest activity date is updated when the profile is read or changed. In your code, you β€œread” the profile (profile.Views + = 1), so it could be what it does, and not a call to Memberhip.GetUser. I have not tested this myself, but hopefully this helps ...

0
source

Source: https://habr.com/ru/post/1400308/


All Articles