Currently we are creating virtual user in Sitecore (9.0.2) database once user is authenticated with backend API as shown below

Sitecore.Security.Authentication.AuthenticationManager.BuildVirtualUser("extranet\\" + Email, true);

We are checking the user is authenticated or not by using below code


Now the problem is, we are adding one more website within same App service that will use same code. Only difference is that site1 and site2 have different virtual directory as shown below

Site1: www.site.come/site1
Site2: www.site.com/site2 

We need to authenticate user against each site separately. Means one user can able to login site1 and site 2 from single browser.

Currently what is happening is that if a user logged into site 1 user is also logged into site 2. this should not happen.

Your help is most welcome.

1 Answer 1


You should use separate security domains for each of the sites.

Instead of using

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

You should use for site1:

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

and for site2:

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

And then check if user is authenticated and belongs to the appropriate site domain.

  • thanks for the help. I have added site name in BuildVirtualUser as you said but when I am cheking user authenticated or not by domain (Sitecore.Context.User.Domain) it is NULL. can you please tell what is wrong with this
    – shahul
    Commented Jul 24, 2023 at 9:32
  • Do you have domain defined in App_Config\Security\Domains.config? E.g. <domain name="site1" ensureAnonymousUser="true" />
    – Marek Musielak
    Commented Jul 24, 2023 at 9:41
  • Thanks now it is coming after adding domain. however facing one another issue, the custom property added to one site user is overriding on another site. virtualUser.Profile.SetCustomProperty("id", 123). Is there any way to store custom property as domain specific user
    – shahul
    Commented Jul 26, 2023 at 11:45
  • virtualUser.Profile.SetCustomProperty(Sitecore.Context.User.Domain+"id", 123)
    – Marek Musielak
    Commented Jul 26, 2023 at 12:29
  • Ok Thanks Marek
    – shahul
    Commented Jul 28, 2023 at 12:24

Your Answer

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

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