5

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?

3
  • Can you check if created and modified fields are part of default view in the target list. If you go to the list settings, at the very bottom of the page, you should see list of views, and one of them should have been marked default. Or SPList.DefaultView should give default view name.
    – sssreddy
    Commented Jan 17, 2013 at 15:55
  • This list has no default view, this is what configuration says me. This list is just used by a webpart. No view is marked as default. Commented Jan 17, 2013 at 19:18
  • Any updates on this, i am facing the exact same issue now?
    – Robban1980
    Commented Mar 18, 2014 at 14:38

2 Answers 2

1

Though I cannot explain why this is happening I can suggest using SPQuery.ViewFilelds to pass the fields you want to return? eg:

  SPQuery query = new SPQuery();
  query.Query = "your query";
  query.ViewFields = "<FieldRef Name='Author' />";
4
  • I was thinking about that.. but I am trying to not modify the software since it need to pass QA again.. =/ Its a environment problem, that can be solved with configuration, since it works at another instance. Commented Jan 16, 2013 at 19:37
  • OK I am wondering if the problem is how you elevating on PowerShell. can you try replacing your line for this one on both scripts? ([xml]$list.GetItems($spQuery)[0].xml).row.ows_Author | Out-Default | Format-Table | Out-Host we you elevating powershell run inside a function and there for it might not output all to the console (just a guess) it wont harm trying :)
    – Renzo
    Commented Jan 16, 2013 at 20:27
  • 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. Commented Jan 17, 2013 at 12:22
  • Regarding QA, this change would actually be a performance improvement, you know :) Commented Jan 23, 2013 at 6:15
0

Can you check if, Created by and Modified by fields are a part of default view in the target list.

1
  • This list has no default view, this is what configuration says me. This list is just used by a webpart. Commented Jan 17, 2013 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.