0

I am using sp 2010. I have a search result webpart with some query inside of it to filter on some content type. I can see results. Is it possible to run this search result webpart under another useraccount with full control permissions? Or something programmatically with runwithelevatedprivileges ?

1
  • doing that could potentially expose things the user isn't supposed to see Commented Jan 9, 2015 at 12:41

1 Answer 1

0

Yes you can extend the CoreResultsWebPart and create a new webpart.

public class ElevatedSearchResults : Microsoft.Office.Server.Search.WebControls.CoreResultsWebPart
{
     ....
}

Now one problem with your approach is, if you elevate the code then all results will get displayed which the current user is not suppose to see. Also if the user who tries to open the link (which he don't have permission) will get an Access Denied error, which will not be a good user experience.

To elevate you should override method GetXPathNavigator.

The complete implementation will look like below

public class ElevatedSearchResults : Microsoft.Office.Server.Search.WebControls.CoreResultsWebPart
{
    protected override System.Xml.XPath.XPathNavigator GetXPathNavigator(string viewPath)
    {
        try
        {
            SPSecurity.RunWithElevatedPrivileges(() =>
            {
                return base.GetXPathNavigator(viewPath);
            });              
        }
        catch
        {
            //LOG ERROR
        }
    }
}

PS: The above code is not tested.

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.