I have a custom login screen, containing some fields which I wish to save as PersonalizedData.
However, I want to do this immediately after authenticating, which means I don't have access to the user data who has just logged in.
I'm using the following code to try and access this user:
string url = HandleLogin();
if (url != null)
{
IPrincipal principal;
principal = AuthenticationProvider.Authenticate(this, Username.Text, Password.Text);
HttpContext.Current.User = principal; // try and set current user in code
CurrentUser.UserData["MyField"] = MyField.Text;
CurrentUser.UserData.Save(); // this doesn't save
PersonalizedData.Load(Username.Text); // try and populate PersonalizedData
PersonalizedData.Current["MyField"] = MyField.Text;
PersonalizedData.Current.Save(); // this doesn't save either
Response.Redirect(url); // normal login redirect
}
As you can see from my comments, the two methods I've tried to set custom data for the user don't work. Can anybody help?
Thanks,
/\dam
Hi Adam!
The following should work:
if( UnifiedPrincipal.Current.Identity.IsAuthenticated )
{
PersonalizedData pd = UnifiedPrincipal.Current.UserData;
pd["ShoeSize"] = "8.5";
pd["FavouritePet"] = "Cat";
pd.Save():
}
Regards,
Johan Olofsson
string url = HandleLogin(); if (url != null) { IPrincipal principal; principal = AuthenticationProvider.Authenticate(this, Username.Text, Password.Text); HttpContext.Current.User = principal; // try and set current user in code CurrentUser.UserData["MyField"] = MyField.Text; CurrentUser.UserData.Save(); // this doesn't save PersonalizedData.Load(Username.Text); // try and populate PersonalizedData PersonalizedData.Current["MyField"] = MyField.Text; PersonalizedData.Current.Save(); // this doesn't save either Response.Redirect(url); // normal login redirect }
As you can see from my comments, the two methods I've tried to set custom data for the user don't work. Can anybody help? Thanks, /\dam