sharepoint - 特征事件有 'null' 个对象

标签 sharepoint sharepoint-2010

public class Feature1EventReceiver : SPFeatureReceiver
{

    public override void FeatureInstalled(SPFeatureReceiverProperties properties)
    {

        string sContextNull = (SPContext.Current == null) ? "Context is NULL" : "Context is OK";
        string sFeatureNull = (properties.Feature == null) ? "Feature is NULL" : "Feature is OK";

        // Some code here
        ...
        ...
    {
}

该功能已成功安装(日志中没有错误)。我的问题是 sContextNull 总是返回 "Context is NULL"。而且 sFeatureNull 也总是返回 "Feature is NULL"。有没有办法获取 SPContext.Currentproperties.Feature 的非空值?

另一种方法 FeatureActivated 返回 Context is NULLFeature is OK。什么鬼?

最佳答案

SPContext.Current

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spcontext.current.aspx

获取 Microsoft SharePoint Foundation 中当前 HTTP 请求的上下文。

SPFeatureReceiver.FeatureInstalled 在功能安装到场时执行,这是通过来自 stsadm 或 powershell 的部署/安装命令完成的,然后通常会触发计时器作业来完成工作。此时没有HTTP请求,所以SPContext.Current返回null。

关于sharepoint - 特征事件有 'null' 个对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5603546/

相关文章:

visual-studio - 无法加载接收器程序集-FileNotFoundException

c# - 无法添加具有空角色定义绑定(bind)集合的角色分配

sharepoint - 如何让SharePoint接受文件名中带有特殊字符的附件?

SharePoint 应用程序部署错误 : 'Failed to install app for SharePoint'

sharepoint - 如何在 Sharepoint 2010 中重命名站点..?

sharepoint-2010 - 如何从 Sharepoint 2010 中的 SocialProfile 获取 SPUser 对象?

c# - 以编程方式设置共享点列表项的字段值

c# - 代码中出现 ListView 阈值超出错误,但 SharePoint 中没有

c# - 开发 Sharepoint Windows 窗体

sharepoint-2010 - 在 Sharepoint 2010 中隐藏列