I am having a huge problem here.
I am executing a query looking for a SPListItem, when I execute this query with user identity it works well, retuning the fields "Author" and "Editor" that I need.
But when I execute the same SPQuery inside a method that is using SPSecurity.RunWithElevatedPrivileges the fields "Author" and "Editor" are not listed.
I have two instances of the same customized application, different content databases, site, but same server.
On the new web site I created a new windows user to Application Pool of this application, used as a managed account inside Sharepoint.
When I use the old user (that is wrong, because this user is computer admin, sharepoint admin, and a lot of other problems to solve talking about best pratices) the SPQuery object returns me perfectly with Author and Editor, but with the new user these fields doesn't get listed.
The Application is the same version, the site was exported and then imported back to the new site.
With the same parameters, different results, depending on RunWithElevatedPrivileges.
The code follows:
public static SPListItem GetCaixaByID(ref SPWeb web, int idCaixa)
{
SPList listCaixa = web.Lists[Config.box_Caixa_ListName];
SPQuery query = new SPQuery();
query.Query =
"<Where>" +
"<Eq><FieldRef Name='SequencialID' /><Value Type='Number'>" + idCaixa + "</Value></Eq>" +
"</Where>";
SPListItemCollection result = listCaixa.GetItems(query);
return result[0];
}
I am using SharePoint 2010.
UPDATE:
I tried using powershell using the both security contexts and the SAME problem, I think that is a security issue but I really don't know how to solve it.
I am putting a print screen of both powershells, same item, different security contexts.
Print Screen showing different security contexts responses http://www.imagetoo.com/images/ps.jpg
UPDATE 2:
I give my pool user rights on the list directly (even begin site administrator) because the list broken the security inheritance, in powershell it worked, but inside my webpart is still not coming. I think that is a security problem.
In Powershell using pool user context, they show me me this values:
RoleAssignments : {Microsoft.SharePoint.SPRoleAssignment, Mi
crosoft.SharePoint.SPRoleAssignment}
AllRolesForCurrentUser : {}
Using the SharePoint Administrator user, they give me this:
RoleAssignments : {Microsoft.SharePoint.SPRoleAssignment, Mi
crosoft.SharePoint.SPRoleAssignment}
AllRolesForCurrentUser : {Total Control, Colaboration}
-- I translated the values to english.
This item was created programatically, and has no inheritance with the list too.
The 2 roleassingments are:
PS C:\Windows\system32> $cx.RoleAssignments[0]
Member RoleDefinitionBindi Parent ParentSecurableObje ngs ct ------ ------------------- ------ ------------------- Administrators {Total Control} Microsoft.ShareP... Microsoft.ShareP...
PS C:\Windows\system32> $cx.RoleAssignments[1]
Member RoleDefinitionBindi Parent ParentSecurableObje ngs ct ------ ------------------- ------ ------------------- Colaborators CD... {Colaboration} Microsoft.ShareP... Microsoft.ShareP...
-- Translated to english
This pool user is member of Administrators group.
Even with this, I cant receive Author and Editor when querying the list under RunWithElevatedPrivileges (that uses pool user)
Any advice?