Terry Cox - SEM, SEO
  ┬á
Tuesday, November 21, 2017                 Register

Terry's Blog
Dec 17

Written by: Terry Cox
12/17/2008 3:23 AM 

I wanted to find a way to display Google Adsense ads for the search results on one of my DotNetNuke driven sites.  I got it to work at Celebrity Couples Online.  I'm sure there is a more professional method, but here were the steps I took.  This method is pretty safe.

  1. Create a new page on your site that is hidden (I called mine GSearch), add a text module to the page, and paste the code that Google provides for search results into that text module using the source input option.  This will become your search results page.  Now you just need to modify your Skin files to pass over the details in the parameter that the Google code needs to see.
     
  2. In your /admin/skins directory, create a copy of these four files.
    1. Search.ascx -> GoogleSearch.ascx
    2. Search.ascx.resx -> GoogleSearch.ascx.resx
    3. Search.ascx.vb -> GoogleSearch.ascx.vb
    4. Search.xml -> GoogleSearch.xml
       
  3. In your /admin/skins/App_LocalResources directory, create a copy of Search.ascx.resx -> GoogleSearch.ascx.resx
     
  4. You will only need to edit two of the above files.To start, open up GoogleSearch.ascx.vb
    1. Change Const MyFileName As String = "Search.ascx" to Const MyFileName As String = "GoogleSearch.ascx"
    2. Change the ExecuteSearch function to the below, inserting your own data where needed
        If Not String.IsNullOrEmpty(searchText) Then
             dim str as string
             str = "<YOUR NEW PAGE URL>?cx=<YOUR CSE ID>%3A72pzbzmchja&cof=FORID%3A9&ie=UTF-8&q=" & Server.UrlEncode(searchText)
        response.redirect(str)
        End If
       
  5. Second, in GoogleSearch.ascx, change CodeFile="Search.ascx.vb" to CodeFile="GoogleSearch.ascx.vb" in top line.
     
  6. In your website skin files, change <%@ Register TagPrefix="dnn" TagName="SEARCH" Src="~/Admin/Skins/Search.ascx" %>  to <%@ Register TagPrefix="dnn" TagName="SEARCH" Src="~/Admin/Skins/GoogleSearch.ascx" %>

Hoping I didn't leave out a step, but it seems to work for me.  I'm not all that thrilled with Google CSE's indexing time however.  I'm seeing it take upwards of two weeks to index new pages, even with me adding the pages to an XML Sitemap and requesting a re-index from the CSE tools.  If you run into problems, reverting only the very last change puts the old search back.  Took a little trial and error!

Tags:

2 comment(s) so far...

Re: Google CSE and DotNetNuke (DNN)

Hi Terry

I am using your example for implementing google cse on to my website and it is working to a point but the page is showing no results in the text/html module any ideas what this could it be am i not putting the google verification key in correctly in to the ascx.vb script or do you think thats ok cause otherwise i guess it would not redirect to the gsearch page.

Any help is much appreciated
Thanks
Martin

By imarewebmaster on   1/28/2010 7:52 AM

Re: Google CSE and DotNetNuke (DNN)

Hi Terry

I am using your example for implementing google cse on to my website and it is working to a point but the page is showing no results in the text/html module any ideas what this could it be am i not putting the google verification key in correctly in to the ascx.vb script or do you think thats ok cause otherwise i guess it would not redirect to the gsearch page.

Any help is much appreciated
Thanks
Martin

By imarewebmaster on   1/28/2010 8:05 AM

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Add Comment   Cancel 
Browse by Date
Subscribe to Blog
Search Posts
Copyright 2007 by Port of Dreams Web Development
beats casque pandora beats kopfhorer beat by dre monster beats beats headphones cheap mont blanc pens