We are creating and updating items in the sitecore tree, we are using SecurityDisabler
to perform the operation.
The system considers the operation is performed by an anonymous user but we need to log the user.
Can you suggest which Sitecore API we need to use so that we can pass a user identity?
our objective is to track changes whether it is from the content author or any program.
2 Answers
From what I know, you cannot do this if you're using SecurityDisabler
.
If you use SecurityDisabler
Sitecore doesn't save the information who made the change.
You should do your changes in UserSwitcher
context:
using (new UserSwitcher(username, isAuthenticated))
{
// your code here
}
If you do this, Sitecore will check access rights for that particular user. So you must be sure user has access rights to edit that item.
We have two options to edit/create a sitecore items using sitecore API
- SecurityDisabler - It is not recommended for your approach/requirement because SecurityDisabler will grant user with administrative access. So the contextUser can do any thing.
- UserSwitcher - It allows a segment of code to run under a specific user instead of current context user.
Here are small code sample with snapshot along with output
Before code reach UserSwitch
After code reach UserSwitch
Referred from this link