【问题标题】:Operation is not valid due to the current state of the object.( SPWebApplication.Update)由于对象的当前状态,操作无效。(SPWebApplication.Update)
【发布时间】:2014-05-27 16:27:59
【问题描述】:

我在尝试以编程方式在 sharepoint 2010 Web 应用程序中添加用户策略时收到此错误:

Operation is not valid due to the current state of the object.

这是一个代码示例:

public Boolean AddUser(SoftwareUser user)
    {
        SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            using (site = new SPSite(siteUrl))
            {
                using (web = site.RootWeb)
                {
                    web.AllowUnsafeUpdates = true;
                    SPUser spUser = web.EnsureUser(user.UserShortname);
                    web.Groups["MySolution Members"].AddUser(spUser);
                    if (spUser != null)
                    {
                        if (user.Email != null)
                        {
                            spUser.Email = user.Email;
                        }
                        spUser.Update();
                        SPWebApplication webApp = site.WebApplication;
                        SPPolicy policy = webApp.Policies.Add(spUser.Name, "deny");
                        policy.PolicyRoleBindings.Add(webApp.PolicyRoles["deny"]);
                        webApp.Update();
                    }
                    web.AllowUnsafeUpdates = false;
                }
            }
        });
        return true;
    }

提前谢谢你。


在堆栈跟踪下方查找:

System.InvalidOperationException: Operation is not valid due to the current state of the object.

System.InvalidOperationException: Operation is not valid due to the current state of the object.
at Microsoft.SharePoint.WebControls.SPControl.SPWebEnsureSPControl(HttpContext context)
at Microsoft.SharePoint.Utilities.SPUtility.ValidateFormDigest()
at Microsoft.SharePoint.Administration.SPPersistedObject.BaseUpdate()
at Microsoft.SharePoint.Administration.SPWebApplication.Update()
at WcfServices.WFService.<>c__DisplayClass2c.<AddUser>b__2b() in C:\SourceCode\DEV-_V5.2.5\WCFServices\SP2010\WcfServices\WcfServices\WFService.svc.cs:line 980
at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass4.<RunWithElevatedPrivileges>b__2()
at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)
at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param)
at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode)
at WcfServices.WFService.AddUser(SoftwareUser user) in C:\SourceCode\DEV-_V5.2.5\WCFServices\SP2010\WcfServices\WcfServices\WFService.svc.cs:line 959
at SyncInvokeAddUser(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

【问题讨论】:

  • 在哪一行出现错误?
  • 你能提供一个堆栈跟踪吗?

标签: wcf sharepoint policy


【解决方案1】:

不要在 Elevated Permission 的委托中调用 .Update() 就在SPSecurity.RunWithElevatedPrivileges下面做吧

【讨论】:

    猜你喜欢
    • 2010-10-18
    • 1970-01-01
    • 2020-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多