0

I am creating virtual user for site 1 using below code

AuthenticationManager.BuildVirtualUser("site1\\"+Email, true);

for site 2 using below code

AuthenticationManager.BuildVirtualUser("site2\\"+Email, true);

Now I want to logout user from site specific. Currently using below code

AuthenticationManager.Logout();
Sitecore.Context.User.Delete();

This will logout and delete user from site1 and site2. But I want to logout from specific site and delete from specific site

Please help me on this.

2 Answers 2

0

Try to put your code inside the below using statement to see if it helps:

 using (new Sitecore.Sites.SiteContextSwitcher(website))
{
  ... 
} 
1
  • Hi Site context is coming corructly using Sitecore.Context.Site. but Sitecore.Context.User is not coming corructly based on site.
    – shahul
    Aug 8 at 11:02
0

You can try the following solutions to make it work. The first approach you can try is using UserSwitcher using the below code.

using (new UserSwitcher("domain\\username"))
{
    // your code here
}

The second approach you can use is to get the currently active user and then use the AuthenticationManager.Logout() to log out the user using the below code.

var virtualUser = Sitecore.Security.Authentication.AuthenticationManager.GetActiveUser();
virtualUser.RuntimeSettings.AddedRoles.Clear();
virtualUser.Roles.RemoveAll();
virtualUser.RuntimeSettings.Save();
Sitecore.Security.Authentication.AuthenticationManager.Logout();

Hope this will solve your issue.

3
  • I want to logout specific domain virtual user not all the active users. the current code which you explained is already using and not working as expected
    – shahul
    Aug 8 at 11:04
  • So did you try to add the code under UserSwitcher? @shahul Aug 8 at 11:29
  • It is not working @sumit
    – shahul
    Aug 8 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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