我是比較新的SharePoint和正在使用2010年我有應用程序中的頁面我試圖建立與下面的代碼有問題的版本:問題與SharePoint 2010應用程序頁面
using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Text;
using Microsoft.SharePoint.Administration;
using Microsoft.Office.Server;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint.Utilities;
namespace SharePointProject5.Layouts.SharePointProject5
{
public partial class ApplicationPage1 : LayoutsPageBase
{
protected void Page_Load(object sender, EventArgs e)
{
SPContext context = SPContext.Current;
StringBuilder output = new StringBuilder();
using(SPSite site = context.Site)
using (SPWeb web = site.AllWebs["BDC_SQL"])
{
UserProfileManager upmanager = new UserProfileManager(ServerContext.GetContext(site));
string ListMgr = "";
string ADMgr = "";
bool allowUpdates = web.AllowUnsafeUpdates;
web.AllowUnsafeUpdates = true;
web.Update();
SPListCollection listcollection = web.Lists;
SPList list = listcollection["BDC_SQL"];
foreach (SPListItem item in list.Items)
{
output.AppendFormat("<br>From List - Name & manager: {0} , {1}", item["ADName"], item["Manager_ADName"]);
UserProfile uProfile = upmanager.GetUserProfile(item["ADName"].ToString());
output.AppendFormat("<br>From Prof - Name & manager: {0} , {1}", uProfile[PropertyConstants.DistinguishedName], uProfile[PropertyConstants.Manager]);
ListMgr = item["Manager_ADName"].ToString();
ADMgr = Convert.ToString(uProfile[PropertyConstants.Manager]);
if (ListMgr != ADMgr)
{
output.AppendFormat("<br>This record requires updating from {0} to {1}", uProfile[PropertyConstants.Manager], item["Manager_ADName"]);
uProfile[PropertyConstants.Manager].Value = ListMgr;
uProfile.Commit();
output.AppendFormat("<br>This record has had its manager updated");
}
else
{
output.AppendFormat("<br>This record does not need to be updated");
}
}
web.AllowUnsafeUpdates = allowUpdates;
web.Update();
}
Label1.Text = output.ToString();
}
}
}
一切運行良好直到我加入'uProfile.Commit();'線。現在,我收到以下錯誤消息:
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.
Source=Microsoft.SharePoint
ErrorCode=-2130243945
NativeErrorMessage=FAILED hr detected (hr = 0x80004005)
NativeStackTrace=""
StackTrace:
at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx)
at Microsoft.SharePoint.Library.SPRequest.ValidateFormDigest(String bstrUrl, String bstrListName)
at Microsoft.SharePoint.SPWeb.ValidateFormDigest()
at Microsoft.Office.Server.UserProfiles.UserProfile.UpdateBlobProfile()
at Microsoft.Office.Server.UserProfiles.UserProfile.Commit()
at SharePointProject5.Layouts.SharePointProject5.ApplicationPage1.Page_Load(Object sender, EventArgs e)
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at Microsoft.SharePoint.WebControls.UnsecuredLayoutsPageBase.OnLoad(EventArgs e)
at Microsoft.SharePoint.WebControls.LayoutsPageBase.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException: System.Runtime.InteropServices.COMException
Message=<nativehr>0x80004005</nativehr><nativestack></nativestack>Updates are currently disallowed on GET requests. To allow updates on a GET, set the 'AllowUnsafeUpdates' property on SPWeb.
Source=""
ErrorCode=-2130243945
StackTrace:
at Microsoft.SharePoint.Library.SPRequestInternalClass.ValidateFormDigest(String bstrUrl, String bstrListName)
at Microsoft.SharePoint.Library.SPRequest.ValidateFormDigest(String bstrUrl, String bstrListName)
InnerException:
我曾嘗試通過在代碼中添加允許不安全的更新,但我仍然得到這個錯誤糾正這一點。
有沒有人對我有任何指導?這將非常感激。
在此先感謝,
馬特。