CurrentUser.GetStringValue of a custom field randomly changes values

Jaroslav Šebok asked on November 28, 2016 13:53

Using Kentico 7.0.52 I have this code which surprisingly works on a dev environment and doesn't work on the live env.

This should update a custom field which it sucessfully does on both environments.

public partial class CMSWebParts_FormZakaznik : CMSAbstractWebPart
{
private UserInfo uInfo;

protected void Page_Load(object sender, EventArgs e)
{
    uInfo = UserInfoProvider.GetFullUserInfo(this.CurrentUser.UserID);
    this.lblActual.Text = this.CurrentUser.GetStringValue("CustomerName", "undefined");
}
protected void btnOk_Click(object sender, EventArgs e)
{
    this.lblError.Visible = false;
    this.lblError.Text = string.Empty;

    if (!string.IsNullOrEmpty(this.cmbZakaznik.SelectedValue))
    {
        uInfo.SetValue("CustomerID", this.cmbZakaznik.SelectedValue);
        uInfo.SetValue("CustomerName", this.cmbZakaznik.SelectedText);
        UserInfoProvider.SetUserInfo(uInfo);

    }
    else
    {
        this.lblError.Visible = true;
        this.lblError.Text = "Error";
    }
}

}

HOWEVER: When I change value of "CustomerName" it keeps randomly displaying last values on page refresh in lblActual.Text or anywhere CurrentUser.CustomerName is called.

The row in the db is updated correctly and does not change.

When I change CustomerName then log out/in again the problem persists. When I change it and login trough incognito mode it still persists.

Recent Answers


Peter Mogilnitski answered on November 28, 2016 14:48 (last edited on November 28, 2016 14:50)

Not sure about your logic, but I would change it this.CurrentUser.GetStringValue("CustomerName", "undefined") to uInfo.GetValue("CustomerName"). For example:

protected void Page_Load(object sender, EventArgs e)
{
    uInfo = UserInfoProvider.GetFullUserInfo(this.CurrentUser.UserID);
    this.lblActual.Text = ValidationHelper.GetString(uInfo.GetValue("CustomerName"), "undefined");
}
protected void btnOk_Click(object sender, EventArgs e)
{
    this.lblError.Visible = false;
    this.lblError.Text = string.Empty;

    if (!string.IsNullOrEmpty(this.cmbZakaznik.SelectedValue))
    {
        uInfo.SetValue("CustomerID", this.cmbZakaznik.SelectedValue);
        uInfo.SetValue("CustomerName", this.cmbZakaznik.SelectedText);
        UserInfoProvider.SetUserInfo(uInfo);
        this.lblActual.Text = uInfo.GetValue("CustomerName");

    }
    else
    {
        this.lblError.Visible = true;
        this.lblError.Text = "Error";
    }
}

P.S. Are using e-commerce module by any chance? To work with the customer you need CustomerInfoProvider not UserInfoProvider.

0 votesVote for this answer Mark as a Correct answer

Roman Hutnyk answered on November 28, 2016 16:10 (last edited on November 28, 2016 16:11)

Do you run web farm? - There might be some issues with servers sync.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.