问题
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.
回答1:
"As shown above it at least calls System.Web.HttpContext.Current twice which is bad." - this is most probably an issue with the decompiler - I am sure they are not calling it twice.
For Elevated Mode you can use this, but it will still require HttpContext
...
SystemManager.RunWithElevatedPrivilege(p =>
{
WorkflowManager.MessageWorkflow(id, itemType, null, "Publish", false, bag);
});
来源:https://stackoverflow.com/questions/48848034/proper-way-to-publish-sitefinity-mediacontent