The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.
public
class
SearchResultsByPermissions : SearchResults
{
}
public
class
SearchResultsByPermissions : SearchResults
{
protected
override
void
InitializeControls(GenericContainer container)
{
Label resultsStats =
this
.ResultsStats;
//this is the original localized stats message. It shows all the results
var resultsStatsMessage = resultsStats.Text;
base
.InitializeControls(container);
if
(
string
.IsNullOrEmpty(
this
.Query))
{
this
.ResultsStats.Text =
string
.Empty;
return
;
}
int
numberOfAllResults = 0;
SearchResults.ISearcher searcher =
this
.GetSearcher();
//these are all the results (not filtered by permissions)
var allResults = searcher.Search(
this
.Query,
this
.IndexCatalogue, 0, 0,
out
numberOfAllResults);
if
(allResults ==
null
)
{
return
;
}
//here we will store only the results we have permissions to see
List<IDocument> securedResultSet =
new
List<IDocument>();
foreach
(var document
in
allResults)
{
var type = document.GetValue(
"ContentType"
);
var ID =
new
Guid(document.GetValue(
"OriginalItemId"
));
if
(TypeResolutionService.ResolveType(type) ==
typeof
(PageNode))
{
var manager = PageManager.GetManager();
//suppress the security checks so the code can be executed even if
//the current user doesn't have enough permissions
manager.Provider.SuppressSecurityChecks =
true
;
var page = manager.GetPageNode(ID);
if
(page !=
null
)
{
ISecuredObject securedObject = (ISecuredObject)page;
if
(SecurityExtensions.IsSecurityActionTypeGranted(securedObject, SecurityActionTypes.View))
{
securedResultSet.Add(document);
}
}
manager.Provider.SuppressSecurityChecks =
false
;
}
}
var numberOfSecuredSearchResults = securedResultSet.Count;
char
[] chrArray =
new
char
[] {
'\"'
};
string
str =
this
.Query.Trim(chrArray);
resultsStats.Text =
string
.Format(resultsStatsMessage, numberOfSecuredSearchResults, HttpUtility.HtmlEncode(str));
this
.ConfigurePager(numberOfSecuredSearchResults);
this
.ResultsList.DataSource =
null
;
int
itemsToSkip =
this
.GetItemsToSkip();
int
itemsToTake =
this
.GetItemsToTake();
ResultsList.DataSource = securedResultSet.Skip(itemsToSkip).Take(itemsToTake);
}
private
int
GetItemsToSkip()
{
if
(
this
.AllowPaging)
{
int
pageNumber =
this
.GetPageNumber(
this
.GetUrlEvaluationMode(),
this
.PageKey, 0,
"PageNumber"
);
if
(pageNumber > 0)
{
return
(pageNumber - 1) *
this
.ItemsPerPage;
}
}
return
0;
}
private
int
GetItemsToTake()
{
if
(!
this
.AllowPaging)
{
return
0;
}
return
this
.ItemsPerPage;
}
}
View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites
Progress collects the Personal Information set out in our Privacy Policy and the Supplemental Privacy notice for residents of California and other US States and uses it for the purposes stated in that policy.
You can also ask us not to share your Personal Information to third parties here: Do Not Sell or Share My Info
We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.
Thank you for your continued interest in Progress. Based on either your previous activity on our websites or our ongoing relationship, we will keep you updated on our products, solutions, services, company news and events. If you decide that you want to be removed from our mailing lists at any time, you can change your contact preferences by clicking here.