Disable search security trimmer?
-
09-12-2019 - |
Question
I'm currently working with a client, one of the requirements is that users have complete access to the search results, regardless user permissions, including anonymous users, Is there a way to disable security trimming?, I have tried running the core results web part with elevated privileges but it doesn’t seem to work for anonymous users.
Thanks!
Solution
I finally found how to run the core results webpart with elevated privileges, here is the code in case someone else needs it:
protected override XPathNavigator GetXPathNavigator(string viewPath)
{
XmlDocument CustomXml = null;
string UserQuery = "";
QueryManager QM = SharedQueryManager.GetInstance(Page, QueryNumber).QueryManager;
UserQuery = QM.UserQuery;
QueryManager SourceManager = SharedQueryManager.GetInstance(Page, QueryNumber).QueryManager;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SearchQueryAndSiteSettingsServiceProxy settingsProxy = SPFarm.Local.ServiceProxies.GetValue<SearchQueryAndSiteSettingsServiceProxy>();
SearchServiceApplicationProxy searchProxy = settingsProxy.ApplicationProxies.GetValue<SearchServiceApplicationProxy>("Search Service Application");
QueryManager queryManager = new QueryManager();
LocationList LocalList = new LocationList();
Location localSearchLocation = new Location("LocalSearchIndex", searchProxy);
LocalList.Add(localSearchLocation);
queryManager.UserQuery = UserQuery;
queryManager.Add(LocalList);
queryManager.IsTriggered(LocalList);
CustomXml = queryManager.GetResults(LocalList);
});
XPathNavigator xPathNavigator = CustomXml.CreateNavigator();
return xPathNavigator;
}
Edit: Although this works to get all the search results, the refinement panel, and paging web part stopped working, I’m currently looking for a way to fix this.
OTHER TIPS
You could try calling the Search web service from elevated code. Just a thought, never tried it before. FWIW this seems like a really odd requirement :)