简体   繁体   English

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

[英]System.InvalidOperationException: Operation is not valid due to the current state of the object.?

I am developing asp.net mvc application for SharePoint Foundation 2010. asp.net application is hosted on one machine and SharePoint Foundation 2010 is hosted on another machine. 我正在为SharePoint Foundation 2010开发ASP.NET MVC应用程序。ASP.NET应用程序托管在一台计算机上,而SharePoint Foundation 2010托管在另一台计算机上。 I have deployed one custom wcf service inside ISAPI folder of SharePoint environment. 我已经在SharePoint环境的ISAPI文件夹中部署了一个自定义wcf服务。 This custom wcf service creates content databases programatically. 此自定义wcf服务以编程方式创建内容数据库。 asp.net application consumes this custom wcf service. asp.net应用程序将使用此自定义wcf服务。 I am using this approach because my scenario is similar to the link - http://blog.sharedove.com/adisjugo/index.php/2012/07/31/creating-site-collections-in-specific-content-database/ . 我使用这种方法是因为我的情况类似于链接-http://blog.sharedove.com/adisjugo/index.php/2012/07/31/creating-site-collections-in-specific-content-database/ Implemeting the above scenario I was getting error - http://social.technet.microsoft.com/Forums/en-US/sharepointdevelopmentprevious/thread/f10d009b-13c4-4942-86b4-2ab8c4f5994d . Implemeting上述情况下,我得到错误- http://social.technet.microsoft.com/Forums/en-US/sharepointdevelopmentprevious/thread/f10d009b-13c4-4942-86b4-2ab8c4f5994d I have solved this error with http://beyondweblogs.com/sharepoint-2010-sppersistedobject-access-denied/ . 我已经使用http://beyondweblogs.com/sharepoint-2010-sppersistedobject-access-denied/解决了该错误。 Now I am getting error - System.InvalidOperationException: Operation is not valid due to the current state of the object. 现在我遇到错误-System.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()

This error is described in above link bolg.sharedove.com. 上面的链接bolg.sharedove.com中描述了此错误。 I think I need to set the following code as described in bolg.sharedove.com 我想我需要按照bolg.sharedove.com中所述设置以下代码

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

I thnik I can not set the above code in wcf service. 我无法在wcf服务中设置以上代码。 I tried to set it in asp.net application but same error has occured. 我试图在asp.net应用程序中设置它,但发生了同样的错误。 Can anuone please tell where should I set this code ? anuone能否告诉我该在哪里设置此代码? If anyone is having different solution then please share. 如果有人有不同的解决方案,请分享。

I simply added reference to System.Web.dll in wcf service application. 我只是在wcf服务应用程序中添加了对System.Web.dll的引用。 Now I can use HttpContext in wcf. 现在我可以在wcf中使用HttpContext了。 I have set the following code in wcf 我在wcf中设置了以下代码

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

Now all the code in wcf is working fine. 现在,wcf中的所有代码都可以正常工作。 I am now able to create content database and site collection programatically. 现在,我可以以编程方式创建内容数据库和网站集。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Microsoft.Lync.Model.LyncClient.BeginSignIn异常:System.InvalidOperationException:由于对象的当前状态,操作无效 - Microsoft.Lync.Model.LyncClient.BeginSignIn Exception: System.InvalidOperationException: Operation is not valid due to the current state of the object 由于 object 的当前 state,操作无效。 IN SSIS - Operation is not valid due to the current state of the object. IN SSIS 由于对象的当前状态,操作无效。 在C#中 - Operation is not valid due to the current state of the object. in C# 由于对象(System.Iinq)的当前状态,因此该操作无效 - Operation is not valid due to the current state of the object (System.Iinq) 由于对象的当前状态(System.Text.Json),操作无效 - Operation is not valid due to the current state of the object (System.Text.Json) System.InvalidOperationException:任务处于无效状态无法启动 - System.InvalidOperationException: The Task is not in a valid state to be started 为什么收到此错误{“由于对象的当前状态,操作无效。”} C# - Why am I getting this error {“Operation is not valid due to the current state of the object.”} C# 由于 object 的当前 state,操作无效。源 microsoft.azure.amqp 在 eventhub 使用 do.net 核心 5 - operation is not valid due to the current state of the object. source microsoft.azure.amqp in eventhub using dotnet core 5 由于对象的当前状态,操作无效。 当我删除一个按钮 - Operation is not valid due to the current state of the object. When I delete a Button Windows Phone的Facebook SDK:InvalidOperationException:由于对象的当前状态,操作无效 - Facebook SDK for Windows Phone: InvalidOperationException: Operation is not valid due to the current state of the object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM