0

I have a code to run a Search Query which I am running through a site which is having Formn Based authnetication configured.

When I am logged in with the FBA user and try to perform a search query then It throws an error as

Sorry, something went wrong.

TECHNICAL DETAILS Error:Server was unable to process request. ---> Attempted to perform an unauthorized operation.

 SPSecurity.RunWithElevatedPrivileges(delegate
                {

resultXml = queryService.Query(xmlQuery); //Error Here

                 });

Can anybody provide me details How to Resolve this ?

Note: This same code is working when running it from a site which does not have FBA setup.

Sigar Dave
  • 2,598
  • 1
  • 20
  • 42

1 Answers1

0

Can you show what your queryServer.Query does? Using RunWithElevatedPrivileges expect a new SPSite/SPWeb object to be created in the elevated call so maybe that may be the issue?

Verthosa
  • 1,671
  • 1
  • 15
  • 37
  • QueryServer.Query will go and Query all the People available and search them according to the query. I tried by creating SPSite and SPWeb objects inside the runwith elevated but failed. with same access denied error – Sigar Dave Sep 14 '16 at 09:15
  • RunWithElevatedPrivileges should run as the application pool account. Does that user have access to the user profile service? – Verthosa Sep 14 '16 at 09:44
  • Actually the main issue is I want to run this using FBA account login?How can i do that? – Sigar Dave Sep 14 '16 at 10:32
  • the project i work on has also FBA enabled and we encounter no problems to run solutions running with elevated privileges. I would use the debugger and inspect which user is running as elevated. Then doublecheck whether he has access to 'Query all people' (you did not really specify if this is from a database or user profile service). – Verthosa Sep 14 '16 at 12:23
  • Thanks verthosa. THe user which is running as elivates is my FBA user.I debug it and check for SPContext.Current.Site.CurrentUser and it is the same as I am logged.(FBA User). I should be App Identity user instead. Also can you please tell me how to check for QUery allusers ? – Sigar Dave Sep 14 '16 at 12:39
  • hmm, check this article: https://social.msdn.microsoft.com/Forums/office/en-US/652bd637-47c1-47dc-89ff-faea6d40b4d5/spsecurityrunwithelevatedprivileges-has-no-effect-against-userprofilemanager-in-forms?forum=sharepointdevelopmentlegacy it's setting the HttpContext to null as some kind of hack – Verthosa Sep 14 '16 at 13:02
  • Hey SigarDave, have you tried this? I remember doing this also but in webservice calls (its not completly clear why I did this but it was also necessary to get things working) – Verthosa Sep 14 '16 at 18:23
  • Verthosa, I tried it but it is not working and returning the FBA user instead of app pool user – Sigar Dave Sep 19 '16 at 09:32
  • ok, then i ran out of ideas, hope that somebody else can help you further – Verthosa Sep 19 '16 at 09:47
  • Thanks a lot verthosa. – Sigar Dave Sep 19 '16 at 09:48