如何使用ASP.NET MVC實現每頁刷新的旋轉廣告塊,類似於SO的做法?如何在ASP.NET MVC中創建旋轉廣告塊?
您是否認爲他們有一個會話變量以及我們當前正在查看的廣告索引,並循環每個請求或其他內容?
如何使用ASP.NET MVC實現每頁刷新的旋轉廣告塊,類似於SO的做法?如何在ASP.NET MVC中創建旋轉廣告塊?
您是否認爲他們有一個會話變量以及我們當前正在查看的廣告索引,並循環每個請求或其他內容?
我會用OpenX,DART,Google Ad Manager,RightMedia,Rubicon,或其他一些廣告經理。
但是,如果我想自己建立它作爲一個練習,我想:
這與您將用於顯示循環報價,隨機推薦用戶或您希望在每個頁面上顯示的任何其他隨機內容的方法相同。
您可以生成一個隨機數字,並將其用作要顯示的廣告的數組鍵,但無法確保均勻曝光,並且在交換貨幣時會導致很多問題。一個爲此目的而構建的應用程序是OpenX。這提供了真正深入的統計數據,它還允許您設置每個廣告需要顯示多少等。它非常強大,許多商業網站都使用它來管理他們的廣告。
我不知道MVC,但有沒有什麼能阻止你使用AdRotator控件?
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.adrotator.aspx
我不得不在MVC中寫一些加權廣告控件,如果可能的話,它不會連續兩次顯示同一個廣告,並且在我的匆忙中,我最終得到了可怕的代碼作爲靈感。
我敢肯定有很多更好的方法可以做到這一點(而且我已經知道這種情況下,當它不應該重複時),但是我花了很短的時間就完成了這項工作。
public List<Ad> GetRandomWeightedAds()
{
/* Generate random order list of ads with duplicates for ViewsPerRotation */
List<Ad> returnList = GetAllAds().SelectMany(s => Enumerable.Repeat(s, s.ViewsPerRotation)).OrderBy(s => Guid.NewGuid()).ToList();
for (int i = 0; i < returnList.Count - 1; i++) /* Compare all but the last element against subsequent element */
{
if (returnList[i].Id == returnList[i + 1].Id)
{
/* If next to an identical element try and find a new spot for the subsequent element */
for (int j = 0; j < returnList.Count; j++)
{
if (returnList[j].Id != returnList[i].Id /* Don't switch identical element back into same pos*/
&& (j<i || j == 0 || j-1 == i || returnList[i].Id != returnList[j - 1].Id) /* When moving before current 'i', don't move into a place after an identical element */
&& (j<i || j == returnList.Count - 1 || j + 1 == i || returnList[i].Id != returnList[j + 1].Id)) /* When moving before current 'i', don't move into a place before an identical element */
{
returnList[i] = returnList[j];
returnList[j] = returnList[i+1]; /* returnList[i+1] == returnList[i] */
break;
}
}
}
}
return returnList;
}
以下博客將爲Ad Rotator的實施做好準備。
1)以下是在ASP.NET中,但仍然完全基於JQuery和簡單。
http://dongavipul.blogspot.in/2011/02/jquery-adrotator-like-aspnet-adrotator.html
2)下面給出了廣告旋轉器助手方法實現。
http://weblogs.asp.net/rashid/archive/2009/04/20/adrotator-for-asp-net-mvc.aspx
我看不出有什麼問題。 – 2009-02-19 07:28:49
@ [KingNestor]:改名非常好,謝謝;現在這是一個普遍的問題。你的城堡現在用石頭代替沙子製成。 – 2009-02-19 16:29:50
沙堡沒有什麼問題,除了朋克小孩在四處踢砸他人的日子。 – ceejayoz 2009-02-19 19:17:00