2013-02-05 52 views
0

我有一個SPItemEventReceiver,除了在給定的IP和端口上通知另一個HTTP服務器使用POST請求來處理事件外別無其他。在哪裏存儲我的SPItemEventReceivers的全局設置?

HTTP服務器與sharepoint運行在同一臺計算機上,所以我用本地主機和固定端口號發送通知。但是由於事件接收器可以在serverfarm中的其他服務器中調用,因此localhost:PORT將不可用。

因此,每次我的HTTP服務器啓動時,都需要將其IP地址和端口保存在SharePoint中的所有EventReceiver都可以訪問的地方,而不管它們在哪個服務器上被調用。

什麼將是一個很好的地方來存儲這樣的全球可用信息?

我想約SPWebService.ContentService.Properties,但我不確定這是否是一個好主意。你怎麼看?

回答

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應用程序的對象。

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

+0

因此,我必須將每個SPWeb上的信息存儲在場中的每個SPWebApplication中的每個SPSite上? –

+0

該物業包可用於多種級別,如SPWeb,SPSite甚至SPFarm級別。雖然我從來沒有在SPFarm上使用過,但我試圖找到一些很好的參考 – Peterson

+0

這些可能會有所幫助:http://www.fivenumber.com/understanding-sharepoint-property-bag-settings/我會嘗試寫一些代碼示例,但我現在無法訪問SharePoint環境。 – Peterson

相關問題