Programmatically Disabling or Enabling Site Search Visibility

The following code snippets are from a web part I built for a client, to assist them with generating new sites. There were new sites being created a few times a day, that all needed to follow similar configurations, but, were all based on the blank site template. Security and other things needed to be modified easily from a single, central interface, which only Site Collection Administrators could access. Each site had to follow several different business rules, and almost every one needed to apply a different set of these, so thus, the web part was created to handle this, as creating site definitions for every possible outcome of the business rules, would have required a new site definition for almost every one of the hundreds of sites that were being created.

One of the thing they needed to be able to manage from their initial configuration, is to be able to allow or not allow search visibility into that site.

The following code snippet will allow you to do just that. (web below is a reference to the specific SPWeb object). Some definition, as well as links to the WSS 3.0 SDK are below the code snippet.

ASPXPageIndexMode specifies the type of page indexing that will occur. Check this reference in the WSS 3.0 SDK which specifies all values possible for WebASPXPageIndexMode. By setting this to Always, ASPX page indexing is always enabled.

Setting SPWeb.NoCrawl, if set to false, will allow crawling of the site.

Now, using the combination of the three above, this will allow indexing of everything, including the ASPX pages within the site to be crawled. If you wanted to crawl everything else within the site, however, did not want to crawl the ASPX pages themselves, you would use the following:

Like this:

Related

About Geoff VaroskyGeoff Varosky is a Senior Architect for BlueMetal Architects, based out of Watertown, MA. He has been architecting and developing web based applications his entire career, and has been working with SharePoint for the past 13 years. Geoff is an active member of the SharePoint community, Co-Founder and Co-Organizer of the Boston Area SharePoint Users Group, co-founder for the Boston Office 365 Users Group, co-organizer for SharePoint Saturday Boston and speaks regularly at SharePoint events and user groups.