我在我的aspx.cs文件中有一个方法,应该确保当前用户遵循当前站点。当我检查ULS时,我收到这个:

tainContent.followItem:异常:Microsoft.SharePoint.SpException: 此页面的安全验证无效。点击你的 Web浏览器,刷新页面,然后再次尝试操作。 --- system.runtime.interopservices.compexception:安全验证 对于此页面无效。单击Web浏览器中的刷新,刷新 页面,并尝试操作 再次.0x8102006d

无法遵循URL http://removedlink/

microsoft.office.server.social.spsocialfollowingManager.Follow: Microsoft.Office.Server.UserProfiles.followedContentException: InternalError:无法遵循该项目 x at. Microsoft.Office.Server.UserProfiles.FollowedContent.followItem(后续后 项目,布尔Isinternal)

我的代码如下所示:

 protected void ToggleUserFollowSite(object sender, EventArgs e)
        {

                var spWeb = SPContext.Current.Web;
                var currentsite = SPContext.Current.Site;
                var currentUser = spWeb.CurrentUser.LoginName;
                SPSecurity.RunWithElevatedPrivileges(delegate
                    {
                        using (var site = new SPSite(spWeb.Site.ID))
                        {
                            using (var web = site.OpenWeb(spWeb.ID))
                            {


                                SPServiceContext context = SPServiceContext.GetContext(currentsite);                                                                      
                                var profile = new UserProfileManager(context);                                    
                                var user = profile.GetUserProfile(currentUser);                                   
                                var followingManager = new SPSocialFollowingManager(user, context);                                    
                                var actorInfo = new SPSocialActorInfo();
                                actorInfo.ActorType = SPSocialActorType.Site;
                                actorInfo.ContentUri = new Uri(web.Url);
                                followingManager.Follow(actorInfo);

                            }
                        }
                    });
            }
.

当我调试时,这是我获得的例外.follow()方法:

{“操作失败,因为发生内部错误。内部 类型名称: Microsoft.Office.Server.UserProfiles.FollowedContentException。 内部错误代码:11。“}

任何相关的帮助是赞赏

有帮助吗?

解决方案

首先,您应该只使用新创建的spsite和spweb实例在runwithelevateprivileges委派中。在代码中更改以下行

SPServiceContext context = SPServiceContext.GetContext(currentsite);

到这个:

SPServiceContext context = SPServiceContext.GetContext(site);
.

另一个问题是页面上的安全验证,您需要调用 ValidateFormDigest 方法在执行高度之前,自代码执行写入操作以来。因此,在代码中的spsecurity.runwithelevatePriveIleges之前添加以下行:

SPUtility.ValidateFormDigest();
.

许可以下: CC-BY-SA归因
scroll top