1

We are using ADFS Authenticator module, when we are trying to create a virtual user, we are getting the below error:

Expecting state ‘Element’.. Encountered ‘Text’ with name ”, namespace ”.

Below is the code I am using in my applications.

Sitecore.Security.Accounts.User vuser = Sitecore.Security.Authentication.AuthenticationManager.BuildVirtualUser(“athakur”, true);

  • Do you have a stack trace? – maz Apr 17 '18 at 14:20
  • You may need to include a domain in the first parameter passed to BuildVirtualUser. – Teeknow Apr 18 '18 at 21:06
1

Here is what worked for me:

                //Specify with the domain name
                var virtualUser = Sitecore.Security.Authentication.AuthenticationManager.BuildVirtualUser(String.Format("extranet\\{0}", user.Email), true);

                // You can add roles to the Virtual user                    virtualUser.Roles.Add(Sitecore.Security.Accounts.Role.FromName("extranet\\Anonymous"));

                // You can even work with the profile if you wish
                virtualUser.Profile.SetCustomProperty("CustomProperty", user.UserName);
                virtualUser.Profile.Email = user.Email;
                virtualUser.Profile.Name = user.DisplayName;
                virtualUser.Profile.FullName = user.UserName;

                virtualUser.Profile.SetCustomProperty("Country", user.Country);

                //And finally, if you wish to login the virtual user                    Sitecore.Security.Authentication.AuthenticationManager.LoginVirtualUser(virtualUser);
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.