GET请求目前不允许更新。要允许更新GET,请在SPWeb上设置'AllowUnsafeUpdates'属性
我有一个隐藏的Web部件,它读取查询字符串值“optout = Yes”。这optout =是,然后我需要更新配置文件属性。如果你看到我的代码。它失败在“userprof.Commit()”和投掷“更新当前不允许在GET请求。要允许一个GET更新,设置的SPWeb的‘AllowUnsafeUpdates’属性”。任何解决方案?GET请求目前不允许更新。要允许更新GET,请在SPWeb上设置'AllowUnsafeUpdates'属性
private void OptOutMemberInvitation()
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
//update the invitee's Profile property
UpdateInviteeOptOutProfile(InviteeConstitID);
});
}
private void UpdateInviteeOptOutProfile(string inviteeSiteColUrl)
{
ServerContext sc = ServerContext.Current;
UserProfileManager upm = new UserProfileManager(sc);
//Get the user profile
Microsoft.Office.Server.UserProfiles.UserProfile userprof = upm.GetUserProfile(MemberConstitID);
SPWeb web = userprof.PersonalSite.RootWeb;
//make sure we can update our list
web.AllowUnsafeUpdates = true;
web.Update();
//Update the OptOut Property on the user's profile.
userprof["OptOut"].Value = "Yes";
userprof.Commit(); //Fails here
//update the list item to persist it to list
web.AllowUnsafeUpdates = false;
//siteCol.Close();
//siteCol.Dispose();
}
看起来您可能会使用两个SPWeb对象,并将AllowUnsafeUpdates设置为错误的。一个会连接到当前的服务器上下文,另一个是userprof.PersonalSite.RootWeb。您将在RootWeb上设置AllowUnsafeProperties,并更新配置文件中的SPWeb(如果有的话)。
顺便说一句,在设置AllowUnsafeProperties后,别忘了做一个web.Update()。
我也在使用这个。仍然出现错误。 UserProfile userprof = man.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName); SPSite site = SPContext.Current.Site; SPWeb web = site.OpenWeb(); //确保我们可以更新我们的列表 web.AllowUnsafeUpdates = true; web.Update(); //更新用户个人资料上的OptOut属性。 userprof [“OptOut”]。Value =“Yes”; userprof.Commit(); web.AllowUnsafeUpdates = false; – James123 2010-04-22 23:18:43
是否可以更改我的代码?请 – James123 2010-04-23 05:31:31
我们已经使用了“SPSecurity.RunWithElevatedPrivileges”,这意味着我们希望使用应用程序池帐户上下文进行此更新过程。但在函数“UpdateInviteeOptOutProfile”中,我们使用了当前的上下文,而不是创建一个新的站点> web对象。
请使用网址或ID创建一个新网站,然后创建网页对象。
此职位帮助我吨人。谢谢。 – trgraglia 2011-04-12 13:47:26
你找到答案了吗? – 2011-09-27 16:04:09