Sharepoint Forum

 
Home » Forum » Sharepoint       Ask a questionRSS Feeds

custom web service generating Operation is not valid due to the curr

  Asked By: Harshini Avchat         Date: Feb 12, 2009      Category: Sharepoint      Views: 475
 

I'm trying to write a custom web service that returns all webs that a
user has full control of. However, I get a "Server was unable to
process request. --> Operation is not valid due to the current state
of the object." error. This is what the code looks like:

[WebMethod]
public string GetWebs()
{
string info = string.Empty;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(SPContext.Current.Site.ID))
{
Type groupType = typeof(SPGroup);
Type userType = typeof(SPUser);

// site.AllWebs seems to generate the error; all code in the
// foreach loop is commented out.
foreach (SPWeb web in site.AllWebs)
{
} // end foreach web

site.RootWeb.Dispose();
} // end using
});

return info;
}

The event log was initially reporting a DCOM error with IIS WAMREG,
but I gave the account launch and local activation rights. Now, I get
no clue from the event log.

Does any one have an idea of what's going on?

Tagged:                        

 

1 Answer Found

 
Answer #1       Answered By: Brooke Lewis          Answered On: Feb 12, 2009       

I figured out my problem. SPContext.Current does not exist when run
inside of SPSecurity.RunWithElevatedPrivileges(). I had to save the
Guid of the site  before entering the elevated state.

 


Your Answer
  • Answer should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].