Twitter <%=Resources.labels.subscribe %>

How To Run Performancing Ads on ASP.NET

  • PerformancingAds Performancing Ads is a great new service that makes monetizing your blog super easy. The service allows you to set up 125 x 125 sized ads on your blog, by logging into their interface and setting up a new "region" on your site. You then download some PHP code, drop it on your site and start displaying ads. The only problem for .NET sites is that Performancing Ads officially supports only PHP sites.

    Considering I run BlogEngine.NET, an ASP.NET blogging platform; it kind of sucked to sign up, set up a region, and then find out that only PHP sites are supported. I really wanted to try Performancing Ads on my site though, so I set out to find a way to do it, and I did! If you look to the right you'll see my Performancing Ads region. I've even sold an ad block already within the first couple of hours running it.

    Here's what to do to get the ads running on your ASP.NET site:

    • 1.  Sign up with Performancing Ads.
    • 2.  Login, and create a new region for your site. (it's super easy no explaination needed)
    • 3. Download the PHP code they give you after setting up a region.
    • 4. Make a new folder in your sites root and put the PHP code you downloaded in it.
    • 5. Follow the instructions here to set up PHP on your Windows box.
    • 6. Add the Region ID # to the perfads method call in perafds.php file. It should look something like this: perfads(1514);
    • 7. Browse to perfads.php in your browser and make sure it works. If it doesn't you've got some fixing to do.
    • The first 7 steps are not unlike they would be if you were running a PHP site. The only difference is that you have to set up Windows and IIS to run PHP. Now comes the trick to embed the PHP generated Performancing Ads into your ASP.NET site. I tried embedding the ads in my page using an iframe and that worked great, up until the point someone actually clicks an ad. Since the ads are in an iframe, they will open in the frame showing only a small portion of the advertiser's landing page. There is javascript code you can put on a page to make it break out of iframes, but it would essentially need to sit on the advertisers pages - and that's not gonna happen. What I decided to do, was scrape my own page (the perfads.php page) using ASP.NET, and embed the resulting string into my ASP.NET page. So to do that you need to:
    • 8. Copy this very basic scraping function into your ASP.NET code behind: (you will need to Import System.NET and System.IO). 

    • public void GetHtmlPage(string strURL)
      {
             // the html retrieved from the page
             String strResult;
             WebResponse objResponse;
             WebRequest objRequest = System.Net.HttpWebRequest.Create(strURL);
             objResponse = objRequest.GetResponse();
    •        // the using keyword will automatically dispose the object
            // once complete
            using (StreamReader sr =
            new StreamReader(objResponse.GetResponseStream()))
            {
               strResult = sr.ReadToEnd();
               // Close and clean up the StreamReader
               sr.Close();
            }
            litHTMLfromScrapedPage.Text = strResult;
           
    • 9. Put an ASP.NET Literal control with ID="litHTMLfromScrapedPage"  into your ASP.NET markup where you want the ads to appear.
    • 10. Call GetHtmlPage passing in the url to your perfads.php page from your page's PageLoad event. As you can see in the last line of code in the GetHtmlPage method, the scraped HTML is assigned to your Literal control's .Text property, essentially placing right into your ASP.NET page!

    Done! Load your ASP.NET page and your Performancing Ads  should appear in your ASP.NET page! If you have any question's about setting up Performancing Ads on your BlogEngine.NET blog or any other ASP.NET website let me know and I'd be glad to help!

     

    Tags:

    Permalink |

Comments (1) -

Yes this is really a good to use ads on your website. Thanks for sharing the info.

I have used OpenX ads on one of my client's site and it is also good one to pick.

Reply

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading


Intro

My name is Brent Lamborn. I´m 35 years old and I live in Nebraska. I've been coding with the .NET Framework since 2003. I'm a former Marine and I have 5 boys.


View Brent Lamborn's LinkedIn profileView Brent Lamborn's profile

Sponsored By

Categories

Tag Cloud

Blog Roll