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.Current 和 properties.Feature 的非空值?
另一种方法 FeatureActivated 返回 Context is NULL 和 Feature 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/