SharePoint 2010 Search customized - Return all results, but user gets access denied when clicking on some
-
8 มีนาคม 2555 4:15
I have a SharePoint 2010 implementation that has an external facing site. We are using a custom membership provider and AD (through an extended site).There are permissions setup for some users tologin. Everyone else can only see the "anonymous" allowed content. We want the "anonymous" users to be able to see all search results, but when they click on the document, they receive access denied message. I believe we need to code the search to run the search part at some elevated permission level and then go back to the users normal permission level. I am not clear on how to go about this. Any ideas? Thanks
KathyTech
ตอบทั้งหมด
-
8 มีนาคม 2555 7:19
if sub sites didn't inherit the permissions from it's parent site then the problem comes.
please check the below link:
MCTS,MCPD Sharepoint 2010. My Blog- http://sharepoint-journey.com
If a post answers your question, please click "Mark As Answer" on that post and "Vote as Helpful- แก้ไขโดย Devendra Velegandla 6 กุมภาพันธ์ 2556 8:37
-
8 มีนาคม 2555 12:11
Override the core results web part in your own custom web part
public class MySearchResults: CoreResultsWebPart
Inside this part, grab the query the user entered
QueryManager queryManager = SharedQueryManager.GetInstance(this.Page).QueryManager;
string kw= queryManager.UserQuery;Elevate permissions and run a new query using the KeywordQuery class
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite siteCollection = new SPSite(SPContext.Current.Site.ID))
{
SearchServiceApplicationProxy elevatedProxy =
(SearchServiceApplicationProxy)SearchServiceApplicationProxy.GetProxy(SPServiceContext.GetContext(siteCollection));
KeywordQuery keywordQuery = new KeywordQuery(proxy);
...keywordQuery.QueryText = kw;
ResultTableCollection results = keywordQuery.Execute();
ResultTable result = results[ResultType.RelevantResults];
DataTable table = new DataTable();
table.Load(result, LoadOption.OverwriteChanges);}
});Create an XML document in the correct format expected by the Core Results web part and return it
XDocument resultsDoc = new XDocument(new XDeclaration("1.0","utf-8",null));
XElement allResultsNode = new XElement("All_Results");
resultsDoc.Add(allResultsNode);for (int i = 0; i < restrictedSites.Rows.Count; i++)
{
allResultsNode.Add(
new XElement("Result",
new XElement("title", table.Rows[i].ItemArray[FIELD_TITLE].ToString()),
...}
allResultsNode.Add(
new XElement("TotalResults", table.Rows.Count.ToString()),
new XElement("NumberofResults", table.Rows.Count.ToString()));return resultsDoc.ToXmlDocument().CreateNavigator();
Scot
Author, Professional Business Connectivity Services
Author, Inside SharePoint 2010 Blog, www.shillier.com
Twitter, @ScotHillier
SharePoint Trainer, Critical Path Training- ทำเครื่องหมายเป็นคำตอบโดย KathTech 11 มีนาคม 2555 11:19
-
12 มีนาคม 2555 19:12
I am trying to implement this but I cannot have it working.
I have placed the code for generating the XML result in the "XPathNavigator GetXPathNavigator(string viewPath)" method, but when I place it on the search reult page it gives me an error: Unable to display this Web Part.
Can you post the full web-part source code?
Thanks.
-
16 เมษายน 2555 8:19
Just getting the search results using elevated privileges is as simple as this:
protected override System.Xml.XPath.XPathNavigator GetXPathNavigator(string viewPath) { XmlDocument xmlDocument = null; SPSecurity.RunWithElevatedPrivileges(delegate() { QueryManager queryManager = SharedQueryManager.GetInstance(this.Page, this.QueryNumber).QueryManager; xmlDocument = queryManager.GetResults(queryManager[0]); }); XPathNavigator xPathNavigator = xmlDocument.CreateNavigator(); return xPathNavigator; }
As for using a replacement KeywordQuery, it works fine, but you need to handle a lot of details, see: http://kjellsj.blogspot.com/2012/04/elevated-search-results-sharepoint-2010.html
- แก้ไขโดย KjellSJ 16 เมษายน 2555 9:25
-
16 เมษายน 2555 11:08
That's what we ended up doing when it was all said and done.
Thanks
Scot
Author, Professional Business Connectivity Services
Author, Inside SharePoint 2010 Blog, www.shillier.com
Twitter, @ScotHillier
SharePoint Trainer, Critical Path Training