手动运行时工作流程具有SPContext.Current,但运行“On Change”时没有?
问题描述:
如果我手动运行此工作流程,它工作正常。当我让它在编辑时自动运行SPContext.Current为空。自动运行时如何访问SPContext.Current?手动运行时工作流程具有SPContext.Current,但运行“On Change”时没有?
答
SharePoint在完全不同的进程下例行运行您的工作流程。至少,你可以期望你的工作流活动下出现:
- 的IIS工作进程,
- 的
owstimer.exe
过程, - 即与SharePoint(例如控制台应用程序)接口的任意可执行文件。
在相对于引发工作流程和的复杂的工作流程情况事件(!)的SharePoint选择将实际执行它的进程。因此,从ASP.NET触发的长时间运行的工作流程(即IIS工作进程)会自动重新计划以在owstimer.exe
下运行。
结果是你不能使用SPContext.Current
。在工作流活动中,您必须使用WorkflowContext
实例,该实例提供了Web
属性。您的活动必须声明WorkflowContext
类型的依赖项属性才能访问它 - 详情请参阅MSDN here。 VS项目模板将为您提供必要的代码。
实施例:
public partial class LogEventActivity: Activity
{
public static DependencyProperty __ContextProperty = DependencyProperty.Register("__Context", typeof(WorkflowContext), typeof(LogEventActivity));
[Browsable(true)]
[ValidationOption(ValidationOption.Required)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public WorkflowContext __Context
{
get
{
return (WorkflowContext)base.GetValue(__ContextProperty);
}
set
{
base.SetValue(__ContextProperty, value);
}
}
}