【问题标题】:Proper Way to Publish Sitefinity MediaContent发布 Sitefinity MediaContent 的正确方法
【发布时间】:2018-02-18 02:59:35
【问题描述】:

我想在 Sitefinity 库中发布 Sitefinity MediaContentDocumentImageVideo)。当我查看文档时,他们使用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);

上面的代码 sn-p 取自他们的documentation

问题是,WorkflowManager 的底层实现使用HttpContext 来检查当前用户是否具有所需的权限。下面的sn-p来自反编译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);
        ...
    }

如上所示,它至少调用了System.Web.HttpContext.Current两次,这是。特别是如果我使用HostingEnvironment.QueueBackgroundWorkItem 或什至使用显然在HttpContext.Current 之外运行的Quartz 延迟执行。

我的问题是,是否有另一种方法可以在 提升模式 中发布 Sitefinity MediaContent 并且完全不依赖于 HttpContext

目前我正在使用 Sitefinity 9.2,据我所知,上述 API 也存在于 Sitefinity 7.3 上。

【问题讨论】:

    标签: sitefinity


    【解决方案1】:

    如上所示,它至少调用了 System.Web.HttpContext.Current 两次,这是不好的。” - 这很可能是反编译器的问题 - 我确信他们不会调用它两次。

    对于提升模式,您可以使用它,但它仍然需要 HttpContext

    ...
    SystemManager.RunWithElevatedPrivilege(p =>
    {
        WorkflowManager.MessageWorkflow(id, itemType, null, "Publish", false, bag);
    });
    

    【讨论】:

    • 这个SystemManager.RunWithElevatedPrivilege是不是使用了之前的HttpContext?我只是用谷歌搜索了一下,发现this 不确定它在QueueBackgroundWorkItem 或Quartz 下的表现如何。它显然也受到issue 的困扰,并且反射(从应用程序本身访问网站网址)不是选项..
    • 它使用 SystemManager.CurrentHttpContext 我认为您可以尝试设置自己(尽管我从未这样做过)。您不能将 Sitefinity 的 ScheduledTask 用于任何后台任务吗?
    • 不幸的是,没有。我不能将它用作已经在任何地方使用 Quartz 的当前框架..
    猜你喜欢
    • 2018-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-28
    • 1970-01-01
    • 1970-01-01
    • 2011-09-06
    • 2018-09-29
    相关资源
    最近更新 更多