Hi, I am kind of new to Sitefinity and needed some help getting started. I am trying to import some Calendar Events programatically during application startup (and potentially also on a schedule). It works fine if I give permissions to to the "Everyone" role to create events. However, if this permission is not set, I get an authorization error:
Error encountered: You are not authorized to 'Create 0' ('General').
The current Principal is showing as "Anonymous".
My code looks something similar to:
EventsManager eventsManager = EventsManager.GetManager();
var eventToAdd = eventsManager.CreateEvent();
Is there a way to bypass permissions check for Application Startup, or Scheduled tasks?
Any help would be appreciated.
The following code solved the issue.
SystemManager.RunWithElevatedPrivilege(d => WorkflowManager.MessageWorkflow(eventId, typeof(Event), null, "Publish", false, bag); );
using(new ElevatedModeRegion(eventsManager ))
Thank you. The CreateEvent method now works fine, however, when I try to publish, I encounter the same error.
This the code that i use to publish the new events:
var bag = new Dictionary<string, string>();
WorkflowManager.MessageWorkflow(eventId, typeof(Event), null, "Publish", false, bag);