在哪里存储我的SPItemEventReceiver的全局设置?

时间:2013-02-05 12:12:39

标签: c# sharepoint

我有一个SPItemEventReceiver除了使用POST请求通知给定IP和端口上的另一个HTTP服务器之外什么都不做。

HTTP服务器与sharepoint在同一台计算机上运行,​​因此我曾经在localhost和固定端口号发送通知。但由于可以在serverfarm中的其他服务器中调用eventreceiver,因此localhost:PORT将不可用。

因此,每次我的HTTP服务器启动时,它都需要将其IP地址和端口保存在SharePoint中的所有EventReceivers都可以访问的地方,无论它们在哪个服务器上被调用。

存储此类全球可用信息的好地方是什么?

我关注SPWebService.ContentService.Properties,但我不确定这是不是一个好主意。你觉得怎么样?

2 个答案:

答案 0 :(得分:3)

好吧,如果您使用的是Sharepoint 2010,我会考虑将这些值存储在属性包中。使用客户端对象模型甚至Javascript / ECMAScript客户端对象模型。这些代码可能对您有帮助。

using (var context = new ClientContext("http://localhost"))
{
  var allProperties = context.Web.AllProperties;
  allProperties["testing"] = "Hello there";
  context.Web.Update();
  context.ExecuteQuery();
}

或使用javascript:

    function getWebProperty() {
        var ctx = new SP.ClientContext.get_current();
        var web = ctx.get_site().get_rootweb();
        this.props =  web.get_allProperties();
        this.props.set_item(“aProperty”, “aValue”);
        ctx.load(web);

        ctx.executeQueryAsync(Function.createDelegate(this, gotProperty), Function.createDelegate(this, failedGettingProperty));
    }

    function gotProperty() {
        alert(this.props.get_item(“aProperty”));
    }

    function failedGettingProperty() {
        alert("failed");
    }

来源: https://sharepoint.stackexchange.com/questions/49299/sharepoint-2010-net-client-object-model-add-item-to-web-property-bag

https://www.nothingbutsharepoint.com/sites/devwiki/articles/Pages/Making-use-of-the-Property-Bag-in-the-ECMAScript-Client-Object-Model.aspx

答案 1 :(得分:2)

实际上有几种在SharePoint中保存配置值的方法:

  • SharePoint对象的属性包SPWebApplication, SPFarm, SPSite,SPWeb,SPList,SPListItem`
  • SharePoint中的“配置”列表 - 只是您可能设置为Hidden = TRUE
  • 的常规列表
  • web.config文件 - 特别是<AppSettings>

Wictor Wilen实际上解释了6 ways to store settings in SharePoint

当你在谈论试图在某处保存设置的外部进程时,通常我会推荐web.config,但是web.config中的每次更改都会导致IISRESET使它不是一个好选择。我强烈建议您使用一个属性包(例如SPWebApplication.Properties包)或您喜欢的网站中的隐藏列表。您可以像这样设置属性包:

SPWebApplication webApplication = ...
object customObject = ...
// set value in hashtable
webApp.Add("MySetting", customObject);
// persist the hashtable
webApp.Update();

看看这有什么好看的?实际上,只要保持对象可序列化,就可以使用包含多个设置的Web应用程序存储对象。