Hiding Page Content From The Search Engine In Sitefinity Using Layout Widgets

by
Ivan Pelovski
Feb 06, 2012

This post will describe how to create a layout widget that hides its content from the search engine in Sitefinity. This type of layout widget is useful if you want to hide a content block from the indexing or you don't want to write the same control logic for every widget you develop. Writing this layout widget is pretty simple. All that has to be done is to extend the built-in control LayoutControl and reuse the layout templates.

So let's start by adding a new class to your SitefinityWebApp project. Give it a proper name (in this sample it is called NonSearchableLayout) and make it to extend the LayoutControl.

The GetIndexRenderMode() method is an extension method. It says whether the page is rendered by the search engine or it is rendered normally. Setting the Visible property of the control to False makes the control to skip the work it usually does when it is visible. It even skips calling the Render method but for any case we'll override the Render method too.

So this is it. Build the SitefinityWebApp project and the layout widget is ready to be registered in Sitefinity. The documentation page for registering custom layout widgets is here, but here is what to be done:

In the main menu, click Administration » Settings.
The Basic settings page appears.

In LayoutTemplate filed enter the following path "~/SFRes/Telerik.Sitefinity.Resources.Templates.Layouts.Column1Template.ascx" (this is the template of the "100%" layout also known as "Single column layout" :) ).

Click Save changes.

Now you can edit one of your pages and give a try to the new layout widget.

I want to add a note about the usage of this layout. You may ask do you need such layout widget for the other template types ("Two columns with 50% width each.", etc.) The good thing is that you can use the other layouts with this new one in various combinations. For example you don't want the content inside one of your layouts to be indexed. Simply drop a non searchable layout and move the other layout inside. Or you may want the content inside the left part of one of your layouts not to be indexed. In this case drop the new layout in the left part of the existing layout and move its content to the new layout. You can even position a layout widget among other widgets (Content Blocks, News Widget, etc) so you can exclude a certain widget from the search and not exclude its neighbor widgets.

The layout widgets of Sitefinity are a really powerful instrument that can be used for purposes not only related to styling. In this case we used them to change the behavior of other widgets in different scenarios.

If you have a question or want to make a suggestion please leave a comment.

9 comments

My scenario: I put the LoginName widget in my page template and I observed that all my site search result shows the administrator name (being myself as the administrator). The reindex action could have pickup the "internal" rendering of all pages and pickup the LoginName value.
Perhaps this could solve my problem.

Robert May 25, 2012

This could be the solution I am looking for.

My scenario: I put the LoginName widget in my page template and I observed that all my site search result shows the administrator name (being myself as the administrator). The reindex action could have pickup the "internal" rendering of all pages (LoginName widget gets the logged in value of the administrator name) and became part of the search result.

Perhaps this could solve my problem. Thanks Ivan.

Robert May 28, 2012

When I followed this code, I get something like "Resource not found.." then I changed
"SitefinityWebApp.Code.NonSearchableLayout" to "SitefinityWebApp.NonSearchableLayout" and it works!

The Site search should also be reindexed to check if the NonSearchableLayout is working. :)

Robert May 29, 2012

I received the following when the site gets uploaded online.

Post cache substitution is not compatible with modules in the IIS integrated pipeline that modify the response buffers. Either a native module in the pipeline has modified an HTTP_DATA_CHUNK structure associated with a managed post cache substitution callback, or a managed filter has modified the response.

In my local machine, its working fine. I am using the Sitefinity Project Manager to browse and administer the website.

Any ideas how to solve this?

Robert May 29, 2012

I received the following when the site gets uploaded online.

Post cache substitution is not compatible with modules in the IIS integrated pipeline that modify the response buffers. Either a native module in the pipeline has modified an HTTP_DATA_CHUNK structure associated with a managed post cache substitution callback, or a managed filter has modified the response.

In my local machine, its working fine. I am using the Sitefinity Project Manager to browse and administer the website.

Any ideas how to solve this?

Nikhil Jun 06, 2012

(Support ID:534180) posted to telerik people regarding issue posted like this, I am seeing the HTML script / style information when I search for map and open the links below link to see to the issue

(http://homecaretechc16.bandyworks.com/VGR/search-result?indexCatalogue=about-us&searchQuery=map&wordsMode=0) . They suggested to implement non searchable layout and provided us to link for development. After implementation of layout control still we are facing same issue please help us to how to fix it.

Nikhil Jun 06, 2012

(Support ID:534180) posted to telerik people regarding issue posted like this, I am seeing the HTML script / style information when I search for map and open the links below link to see to the issue

(http://homecaretechc16.bandyworks.com/VGR/search-result?indexCatalogue=about-us&searchQuery=map&wordsMode=0) . They suggested to implement non searchable layout and provided us to link for development. After implementation of layout control still we are facing same issue please help us to how to fix it.

Aaron Jun 13, 2012

I am also having this issue.

Post cache substitution is not compatible with modules in the IIS integrated pipeline that modify the response buffers. Either a native module in the pipeline has modified an HTTP_DATA_CHUNK structure associated with a managed post cache substitution callback, or a managed filter has modified the response

Tools

Sitefinity Professional Services

Progress, Telerik, Sitefinity and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries.