AdSenseASP.NET - Articles


[ Home/About | ASP.NET 2.0 WebControls | Live Demo! | FAQ | Glossary | Articles | Download | Feedback | Forum ]

Spread a word - link to us and get money directly to your AdSense account!

AdSenseASP.NET: Free ASP.NET 2.0 web controls for Google AdSense - Freeware C# Open Source


If you read the article I guess you are a .NET developer and it's not a big deal for you to copy-paste Google AdSense javascript code to your website pages. If there are many pages you could reuse it by using ASP.NET user controls.

That's fine until a moment you want flexibly manage AdSense settings and track AdSense clicks on individual basis using custom AdSense channels.

That happens to me when I started to develop few web sites supposed to be monetized by Google AdSense. I had next requirements before starting development of ASP.NET server controls for displaying Google AdSense blocks - http://AdSenseASP.NET/.

I wanted:

So I've developed next web controls:

Configuration module

The library comes with a configuration module uses standard .NET 2.0 approach.

First of all we need to register a configuration section and config section handler.


<configSections>
	<sectionGroup name="SharpEdged">
		<section name="AdSense" type="AdSenseASP.NET.Configuration.AdSenseConfigSection, AdSenseASP.NET"/>
	</sectionGroup>
</configSections>

Then specify configuration section itself and a set of AdSense publisher settings we will reference from our ASP.NET controls.


<SharpEdged>
	<AdSense defaultPublisherID="pub-0194206828430201" defaultRenderMode="Production">
		<publishers>
			<add name="Alexander.Trakhimenok" id="ca-test">
				<channels>
					<add name="Your-Own-AdSense-Channel-Name" id="AdSene channel ID"/>
				</channels>
			</add>
		</publishers>
	</AdSense>
</SharpEdged>

Before use a server control on an ASP.NET page (*.aspx) or ASP.NET user control (*.ascx) you have to register the AdSense ASP.NET assembly withing the markup code:


<%@ Register Assembly="AdSenseASP.NET" TagPrefix="wc" Namespace="AdSenseASP.NET" %>

Now you are ready to place a web control to a page:


<wc:AdSenseAdUnit
    ID="AdSenseAdUnit2"
    runat="server"
    AdUnitFormat="Sqr_LargeRectangle_336x280"
    EnableViewState="false"
    ColorTitle="Black"
    ColorUrl="Navy"
    RenderMode="Production" />

AdSense output resut is on right hand side:

In next article you'll know how to setup AdSense colors from ASP.NET web.config file.