问题描述
大家好,我是sharepoint 2010项目的新手。当我浏览代码时,在许多地方我发现SPWeb.AllowUnsafeUpdates属性设置为true,即使任何列表中没有更新。只有一些列表数据提取才能完成。这是否相关,而任何列表中没有更新才能将AllowUnsafeUpdates设置为true?
Hi All, I am new to sharepoint 2010 project. When I went through the code, in many places i found SPWeb.AllowUnsafeUpdates property set to true, even when there is no updations in any of the lists. There is some list data fetching is only done. Is this relevant while there is no updation in any of the lists to use AllowUnsafeUpdates to be set to true?
SPWeb thisWeb = workflowProperties.Web;
thisWeb.AllowUnsafeUpdates = true;
SPList EmployeeDetails = thisWeb.Lists[BasicEmployeeDetailsList];
SPList list = workflowProperties.Web.Lists[workflowProperties.List.ID];
SPListItem compensatoryLeaveItem = workflowProperties.Item;
DataTable creatermail = new DataTable();
editurl = workflowProperties.SiteUrl.ToString() + list.DefaultEditFormUrl + "?ID=" + compensatoryLeaveItem["ID"].ToString() + "&Popup=false";
string EmployeeDetailsID = compensatoryLeaveItem["Created By"].ToString().Substring(compensatoryLeaveItem["Created By"].ToString().IndexOf('#') + 1);
string listQuery = "<Where><Eq><FieldRef Name='LoginName' /><Value Type='User'>" + EmployeeDetailsID + "</Value></Eq></Where>";
SPQuery query = new SPQuery();
query.Query = listQuery;
SPListItemCollection createrCol = EmployeeDetails.GetItems(query);
creatermail = createrCol.GetDataTable();
createdbymail = creatermail.Rows[0][FieldMail].ToString();
creater = creatermail.Rows[0][FieldFullName].ToString();
GetHrDetails(thisWeb);
thisWeb.AllowUnsafeUpdates = false;
推荐答案
AllowUnsafeUpdates = true
用于网络,完成后你需要将其设置为假。
所以它与在网上更新任何内容时,请使用 AllowUnsafeUpdates
选项。
阅读全文:
希望这有帮助!
for the web and after you have done you need to set it back to false.
So it is not relevant to use AllowUnsafeUpdates
option when updating nothing in web.
Read full article here : Why do I need to use AllowUnsafeUpdates?
Hope this helps!
这篇关于是否需要在sharepoint中获取列表项时设置allowunsafeupdates属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!