2015-10-19 121 views
0

我有這樣的代碼來創建有條件SharePoint列表(排序的UPSERT的):爲什麼這被認爲是Sharepoint中的「不安全更新」?

private void ConditionallyCreateList() 
{ 
    SPWeb site = SPContext.Current.Web; 
    // Check to see if list already exists; if so, exit 
    if (site.Lists.TryGetList(listTitle) != null) return; 

    SPListCollection lists = site.Lists; 
    SPListTemplateType listTemplateType = new SPListTemplateType(); 
    listTemplateType = SPListTemplateType.GenericList; 
    string listDescription = "This list retains vals inputted for the Post Travel form"; 
    Guid ListId = lists.Add(listTitle, listDescription, listTemplateType); 
    . . . 

這個工作時,首先創建,並在應用程序的後續execustions。

不過,我做了一些激進的重構到列表結構,並刪除了舊的,所以(我希望)一個新的具有新的結構將被創建。然而,而不是讓一個重構的名單,我得到這個在最後一行如上圖所示:

Microsoft.SharePoint.SPException was unhandled by user code 
    Message=Updates are currently disallowed on GET requests. To allow updates on a GET, set the 'AllowUnsafeUpdates' property on SPWeb. 

我能夠通過添加指定的代碼來解決此問題:

site.AllowUnsafeUpdates = true; 

...但爲什麼這是必要的嗎?爲什麼創建一個不應該存在的列表(我從Sharepoint「所有網站內容」bazaar中刪除它)有問題(可能是一個'不安全的更新')?

回答

1

在保護自己免受之類的東西XSS和會話劫持的努力,大多數更新到SharePoint站點都依賴於一種形式消化嵌入用戶從中使得變化在同一頁上的控制。如果觸發更新時,表單摘要控件中的信息不存在,則SharePoint會採用最差的方式。這在服務器端代碼可能以高權限執行的情況下尤爲重要。

正如您發現的那樣,通過在進行任何更改之前立即將SPWeb對象的AllowUnsafeUpdates屬性切換爲true,可以輕鬆避免此情況。

相關問題