Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create rotating ad blocks in ASP.NET MVC?

Tags:

How would you implement a rotating ad-block with each page refresh, similar to what SO does, using ASP.NET MVC?

Do you think they have a session variable with what ad index we are currently viewing and cycle it each request or something else?

like image 273
KingNestor Avatar asked Feb 19 '09 02:02

KingNestor


People also ask

What is Razor in MVC with example?

Razor is a markup syntax that lets you embed server-based code into web pages using C# and VB.Net. It is not a programming language. It is a server side markup language. Razor has no ties to ASP.NET MVC because Razor is a general-purpose templating engine.

What is @: In Cshtml?

This operator is useful in conjunction with other Razor server side operators when you want to output something as a literal text. For example: @if (model. Foo) { @:Some text to be written directly. }

What does scaffolding in MVC application mean?

ASP.NET Scaffolding is a code generation framework for ASP.NET Web applications. Visual Studio 2013 includes pre-installed code generators for MVC and Web API projects. You add scaffolding to your project when you want to quickly add code that interacts with data models.


1 Answers

I would use OpenX, DART, Google Ad Manager, RightMedia, Rubicon, or some other ad manager.

However, if I wanted to build it myself as an exercise, I would:

  1. Create a database table of advertisements
  2. In my base controller, select a random advertisement into the ViewData
  3. Add a partial view to your master page to render the ad
  4. [Most importantly] Use Phil Haack's MVC-style version of "donut caching"

This is the same approach you would use to display a cycled quotation, a randomly featured user, or any other random content that you want to display on every page.

like image 167
Portman Avatar answered Oct 11 '22 18:10

Portman