Using Google Adsense With BlogEngine.NET 2.0

by Rob 10. June 2011 21:30

If you've used BlogEngine in the past; you might be familar with the AdSense widget or the Literal widget....but they don't seem to work in 2.0!  So, how do you get your Google Adsense Ads into your site?

First, log in and go to your home page.  Look for the 'widget' dropdown on the right-hand side of the page.

Select 'Textbox' and click the 'Add' button.  You should see a new TextBox Widget Appear.  Click 'Edit'

You should see something that looks like this.  Unclick 'Show title'.

DO NOT paste your adsense code into the textbox.  It won't work!  The TextBox widget will escape important characters.  Just type the word 'TEST' and hit save.

Now browse to your webserver and enter the 'App_Data/datastore/widgets/' folder.  Locate a .xml file with a timestamp of a few seconds go.  Download it and open it.  

Take the Javascript from Google's Adsense page (it should look like this)

<script type="text/javascript"><!--
google_ad_client = "ca-pub-2052174281835744";
/* Blog - Side Bar Small */
google_ad_slot = "3419877836";
google_ad_width = 250;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

And replace all of the < with &lt; replace all of the > with &gt; and replace all of the " with &quote; - then remove the endlines.  Paste this line into the value field.

 

<?xml version="1.0" encoding="utf-8"?>
<SerializableStringDictionary>
  <SerializableStringDictionary>
    <DictionaryEntry Key="content" Value="<script type="text/javascript"><!--google_ad_client = "ca-pub-2052174281835744";/* Blog - Side Bar Small */google_ad_slot = "3419877836";google_ad_width = 250;google_ad_height = 250;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>" />
  </SerializableStringDictionary>
</SerializableStringDictionary>

 

Hit save and upload to the server.  Now, visit your site....TaDa!  It's not as easy as the old AdSense widget or the old Literal widget; but it gets the job done.  

Categories:
Comments are closed