I have a .NET Web Application that acts as a front-end site for users, and this application leverages a separate SharePoint 2013 Application to serve data to the users. One of the tasks was to implement Search on the front end by leveraging SharePoint's own search. I solved this problem by writing my Search queries using server side code.
The problem I'm encountering is that although search results are returned correctly, there is no security trimming on them. For example, if I have 2 documents, Document A and Document B, and I have a user who can only access Document A, a search by the user still returns both documents. After some research, I figured that this might be due to the way I create my search query, but so far I haven't been able to find a solution to the problem. Here is the code that creates the Search Query
// Get the result source and the search service proxy string resultSourceName = ConfigurationManager.AppSettings["ResultSourceName"]; SearchServiceApplicationProxy searchProxy = (SearchServiceApplicationProxy)SearchServiceApplicationProxy.GetProxy(SPServiceContext.GetContext(spSite)); FederationManager federationManager = new FederationManager(searchProxy); SearchObjectOwner searchOwner = new SearchObjectOwner(SearchObjectLevel.Ssa, spSite.RootWeb); Microsoft.Office.Server.Search.Administration.Query.Source resultSource = federationManager.GetSourceByName(resultSourceName, searchOwner); // Create a query object, set its result source and set the properties to return in the search results table KeywordQuery query = new KeywordQuery(spSite); query.SourceId = resultSource.Id;
I have two questions:
- What is the problem with the above code that is causing this security trimming issue?
- If it is not the code, what are the other possible causes of this issue?