系统.InvalidOperationException:由于对象的当前状态,操作无效

本文关键字:状态 无效 操作 对象 InvalidOperationException 于对象 系统 | 更新日期: 2023-09-27 18:10:45

我正在为SharePoint Foundation 2010开发asp.net mvc应用程序。asp.net应用程序托管在一台机器上,而SharePoint Foundation 2010托管在另一台机器上。我在SharePoint环境的ISAPI文件夹中部署了一个自定义wcf服务。这个自定义wcf服务以编程方式创建内容数据库。Asp.net应用程序使用此自定义WCF服务。我使用这种方法是因为我的场景类似于链接- http://blog.sharedove.com/adisjugo/index.php/2012/07/31/creating-site-collections-in-specific-content-database/。实现上述场景,我得到错误- http://social.technet.microsoft.com/Forums/en-US/sharepointdevelopmentprevious/thread/f10d009b-13c4-4942-86b4-2ab8c4f5994d。我已经用http://beyondweblogs.com/sharepoint-2010-sppersistedobject-access-denied/解决了这个错误。现在我得到错误-系统。InvalidOperationException:由于对象的当前状态,操作无效。

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.SPPersistedChildCollection`1.Add(T newObj, Boolean ensure)
   at Microsoft.SharePoint.Administration.SPPersistedChildCollection`1.Ensure(T newObj)
   at Microsoft.SharePoint.Administration.SPContentDatabaseCollection.Add(Guid newDatabaseId, String strDatabaseServer, String strDatabaseName, String strDatabaseUsername, String strDatabasePassword, Int32 warningSiteCount, Int32 maximumSiteCount, Int32 status, Boolean provision, Guid lockId, Int32 addFlags)
   at Microsoft.SharePoint.Administration.SPContentDatabaseCollection.Add(String strDatabaseServer, String strDatabaseName, String strDatabaseUsername, String strDatabasePassword, Int32 warningSiteCount, Int32 maximumSiteCount, Int32 status)
   at Niks.SP2010.SPHostedWCFService1.SPHostedWCFService.<createContentDb>b__7()
   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 Niks.SP2010.SPHostedWCFService1.SPHostedWCFService.createContentDb()
   at Niks.SP2010.SPHostedWCFService1.SPHostedWCFService.<>c__DisplayClass3.<GetName>b__1()
   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 Niks.SP2010.SPHostedWCFService1.SPHostedWCFService.GetName()

此错误描述在上面的链接bolg.sharedove.com。我想我需要设置下面的代码描述在bolg.sharedove.com

var storeContext = HttpContext.Current; 
HttpContext.Current = null; 
// do your code 
HttpContext.Current = storeContext;

我想我不能在wcf服务中设置以上代码。我试图在asp.net应用程序中设置它,但发生了同样的错误。谁能告诉我这个密码应该设置在哪里?如果有人有不同的解决方案,请分享。

系统.InvalidOperationException:由于对象的当前状态,操作无效

我只是在wcf服务应用程序中添加了对System.Web.dll的引用。现在我可以在wcf中使用HttpContext。我在wcf

中设置了以下代码
var storeContext = HttpContext.Current; 
HttpContext.Current = null; 
// do your code 
HttpContext.Current = storeContext;

现在wcf中的所有代码都工作正常。我现在能够以编程方式创建内容数据库和站点集合。