我似乎無法找到爲什麼但LastActivityDate總是更新,即使當我將Membership.GetUser(userName,false)設置爲false,所以它不會更新LastActivityDate。我沒有任何其他代碼訪問GetUser的任何其他代碼。所以我在配置文件中創建了一個名爲LastActivity的屬性,這有點類似,但我不明白爲什麼GetUser每次刷新頁面時總是更新LastActivityDate。Membership.GetUser(userName,isOnline)總是更新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;
}
}
如果是這種情況,我可以做些什麼來改變/避免配置文件。在這種情況下保存 – ONYX 2012-03-08 00:32:11
文檔說:「此屬性值只能由默認配置文件提供程序修改。默認配置文件提供程序不會影響LastActivityDate屬性的值。「所以如果你製作了自己的提供商,我想你可以避免更新。我從來沒有這樣做過,但看看[實現配置文件提供程序](http://msdn.microsoft.com/zh-cn/library/0580x1f5.aspx)。這可能是很多工作,雖然... – joshuahealy 2012-03-08 00:56:29
你的其他選擇是在個人資料中添加自己的「活動日期」屬性並自己手動更新 – joshuahealy 2012-03-08 00:56:58