More in this section

Forums / Developing with Sitefinity / Swapping Templates for Search

Swapping Templates for Search

2 posts, 0 answered
  1. Michael
    Michael avatar
    7 posts
    Registered:
    19 Dec 2008
    09 Jan 2009
    Link to this post
    I'm in the middle of rearchitecting our website so we can make a move to Sitefinity 3.6 when it gets released.  I'm using Sitefinity 3.5 SP1 at the moment to prepare myself.

    I've got almost everything figured out with one exception...search.

    I've bought into the fact that Sitefinity is using a spider instead of a data search, which means that the contents of the skin get intermingled with the true page contents in the search results.

    Our current system works the same way, so in our current system, I have an HttpHandler that detects if it is our spider calling the page and if it is, it swaps the master page out for a bare-bones master page that only has the content itself (no navigation or anything else).

    I can't use the HttpHandler method with Sitefinity and I don't want to drop PreInit code on every single page in the site since master pages don't have a preinit event.

    How would I do this with Sitefinity so that my search results look clean?
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    12 Jan 2009
    Link to this post
    Hello Michael,

    You can use Telerik.CmsContext.IsCrawlerRequest in order to check if the pages are visited by our Search Engine. There are two approaches for that:
    1. All CMS pages are inheriting from the InternalPage class. You can create custom InternalPage class which takes care about the IsCrawlerRequest check in OnPreInit event:
    1. - Create a new class in the  App_Code folder that inherits from Telerik.Cms.Web.InternalPage and override OnPreInit method. Enter your logic in this method Replace the declaration of InternalPage class with the name of your newly created class in the following file ~/Sitefinity/cmsentrypoint.aspx. The file should look like this: 
    2. protected override void OnPreInit(EventArgs e)   
      {   
        base.OnPreInit(e);   
        if (Telerik.CmsContext.IsCrawlerRequest) 
                this.Theme = "SearchEngineFriendlyTheme";   
      }   
    3. cmsentrypoint.aspx:
      <%@ Page Language="C#" MasterPageFile="~/App_Master/Dummy.master" Inherits="CustomPage" %> 
       

    This way, all of your pages will inherit this functionality.

    The second way is with HttpModule, here is a pseudo code:
    using System; 
    using System.Web; 
    using Telerik; 
    using Telerik.Cms; 
    using Telerik.Cms.Data; 
     
    namespace CustomHttpModules 
        public class SFCrawlerCheckModule : IHttpModule 
        { 
            public void Dispose() 
            { 
            } 
     
            public void Init(HttpApplication context) 
            { 
                context.BeginRequest += new EventHandler(context_BeginRequest); 
            } 
     
            void context_BeginRequest(object sender, EventArgs e) 
            { 
                ICmsUrl p = Telerik.CmsContext.CurrentUrl; 
                 
                if (Telerik.CmsContext.IsCrawlerRequest) 
                { 
                     //get the page with ID p.PageID 
                     // and change its properties 
                } 
            } 
        } 

    I hope this will help you.

    Best wishes,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
2 posts, 0 answered