I want to publish Sitefinity MediaContent
(Document
, Image
, and Video
in Sitefinity Library). As i look on the documentation, they gave an example using WorkflowManager
:
//Publish the DocumentLibraries item. The live version acquires new ID.
var bag = new Dictionary<string, string>();
bag.Add("ContentType", typeof(Document).FullName);
WorkflowManager.MessageWorkflow(masterDocumentId, typeof(Document), null, "Publish", false, bag);
Code snippet above is taken from their documentation.
The problem is, the underlying implementation of WorkflowManager
uses HttpContext
to check whether the current user has the required privilege. The snippet below is from decompiling the Telerik.Sitefinity.dll
:
public static string MessageWorkflow(System.Guid itemId, System.Type itemType, string providerName, string operationName, bool isCheckedOut, System.Collections.Generic.Dictionary<string, string> contextBag)
{
....
dictionary.Add("operationName", operationName);
dictionary.Add("itemId", itemId);
dictionary.Add("providerName", providerName);
dictionary.Add("isCheckedOut", isCheckedOut);
dictionary.Add("contextBag", contextBag);
dictionary.Add("culture", System.Globalization.CultureInfo.CurrentCulture.Name);
dictionary.Add("httpContext", System.Web.HttpContext.Current);
if (workflowDefinition != null)
{
dictionary.Add("workflowDefinitionId", workflowDefinition.Id);
}
contextBag.Add("userHostAddress", System.Web.HttpContext.Current.Request.UserHostAddress);
...
}
As shown above it at least calls System.Web.HttpContext.Current
twice which is bad. Especially if i have exection deferred using HostingEnvironment.QueueBackgroundWorkItem
or even using Quartz that runs outside HttpContext.Current
obviously.
My question is, is there another way to publish Sitefinity MediaContent
in Elevated Mode and did not depend on HttpContext
at all?
Currently i am using Sitefinity 9.2, as far as i am aware, the APIs above also exists on Sitefinity 7.3.
SystemManager.RunWithElevatedPrivilege
uses the previousHttpContext
? i just googled it a bit and found this not sure how it will behave underQueueBackgroundWorkItem
or Quartz.. it also plagued with this issue apparently, and reflection (accessing the website url from the application itself) is not an option.. – Gleeson