Version 7.x > API > How to set a scope to a specific user context? View modes: 
User avatar
Certified Developer v6
Certified Developer v6
Dave - 1/21/2014 8:33:06 AM
How to set a scope to a specific user context?

I'm trying to wrote a scoped block of code that runs under a specific user context (that would replace CMSContext.CurrentUser). Something along the lines of the following:
using (CMSUserContext context = new CMSUserContext("some_user")) {
//code in here has "CMSContext.CurrentUser as "some_user", not the currently logged in user

Is this possible?

User avatar
Kentico Consulting
Kentico Consulting
Kentico_RichardS - 1/23/2014 1:15:37 AM
RE:How to set a scope to a specific user context?

Thank you for your message.

Why would you want to run the code in a different context? Most of Kentico API providers will take an instance of UserInfo as a parameter. You might consider getting the UserInfo you need and pass it to the methods. Im not sure what the goal of your code is.

In any case you could log out the current user by method:


and then log in the user with Authentication helper -> authenticate user method.

You can see the example here -> http://devnet.kentico.com/docs/devguide/membership_api_examples_managing_users.htm

Let me know if you need anything else.

Kind regards,
Richard Sustek