2010-04-22 2 views
3

쿼리 문자열 값 "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(); 
} 
+0

이 게시물은 나를 도와줍니다. 고맙습니다. – trgraglia

+0

대답을 찾았습니까? –

답변

0

두 개의 SPWeb 개체를 사용하고 잘못된 AllowUnsafeUpdates를 설정할 수있는 것처럼 보입니다. 하나는 현재 서버 컨텍스트와 연결되고 다른 하나는 userprof.PersonalSite.RootWeb입니다. RootWeb에 AllowUnsafeProperties를 설정하고 프로필의 SPWeb을 업데이트합니다 (있는 경우).

아직 끝나면 AllowUnsafeProperties를 설정 한 후에 web.Update()를 수행하는 것을 잊지 마십시오.

+0

나는 이것을 사용하고 있습니다. 여전히 오류가 발생합니다. UserProfile userprof = man.GetUserProfile (SPContext.Current.Web.CurrentUser.LoginName); SPSite site = SPContext.Current.Site; SPWeb 웹 = site.OpenWeb(); // 목록을 업데이트 할 수 있는지 확인하십시오. web.AllowUnsafeUpdates = true; web.Update(); // 사용자 프로필의 OptOut 속성을 업데이트하십시오. userprof [ "OptOut"]. 값 = "예"; userprof.Commit(); web.AllowUnsafeUpdates = false; – James123

+0

내 코드를 변경하는 것이 가능합니까? 부디 – James123

1

"SPSecurity.RunWithElevatedPrivileges"는이 업데이트 프로세스에 대해 응용 프로그램 풀 계정 컨텍스트를 사용하고자 함을 의미합니다. 그러나 "UpdateInviteeOptOutProfile"함수 내에서 새로운 사이트> 웹 객체를 만드는 대신 현재 컨텍스트를 사용했습니다.

URL 또는 ID를 사용하여 새 사이트를 만든 다음 웹 개체를 생성하십시오.

관련 문제