工作流在手动运行时有 SPContext.Current 但在“更改时”运行时没有?
如果我手动运行此工作流程,它工作正常。当我让它“编辑时”自动运行时,SPContext.Current 为空。当 SPContext.Current 自动运行时,如何访问它?
If I run this workflow manually it works fine. When I let it run automatically "on edit" SPContext.Current is null. How do I get access to SPContext.Current when it is run automatically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SharePoint 通常在完全不同的流程下运行您的工作流程。至少,您可以期望您的工作流活动出现在:
对于触发工作流的事件和工作流场景的复杂性 (!!)SharePoint 选择实际执行它的流程。因此,长时间运行的工作流在从 ASP.NET(即 IIS 工作进程)触发时会自动重新安排在
owstimer.exe
下运行。结果是您无法使用
SPContext.Current
。在工作流活动中,您必须使用提供Web
属性的WorkflowContext
实例。您的活动应声明WorkflowContext
类型的依赖属性才能访问它 - 请在 MSDN 此处。 VS 项目模板将为您提供必要的代码。例子:
SharePoint routinely runs your workflows under completely different processes. At least, you can expect your workflow activities to appear under:
owstimer.exe
process,In respect to the event that triggered the workflow and the complexity of the workflow scenario (!!) SharePoint selects the process that will actually execute it. Thus a long running workflow when triggered from ASP.NET (i.e. the IIS worker process) is automatically rescheduled to run under
owstimer.exe
.The result is you cannot use
SPContext.Current
. In workflow activities you have to use aWorkflowContext
instance which provides aWeb
property. Your activites shall declare a dependency property of typeWorkflowContext
to get access to it — read more in MSDN here. The VS item template will provide you with the necessary code.Example: