我已经创建了一个母版页,它使用3个System.Web.UI.WebControls.AdRotator实例,每个实例都由相同的广告元素XML文件支持。例如,
<asp:adRotator AdvertisementFile="/ads.xml" Runat="server"/>
*** ads.xml ***
<Advertisements>
<Ad>
<ImageUrl>/Path/Banner.gif</ImageUrl>
<NavigateUrl>http://www.google.com</NavigateUrl>
<AlternateText>
The best search engine in the world!
</AlternateText>
<Impressions>3</Impressions>
</Ad>
</Advertisements>问题是,有时相同的广告会在给定的时刻出现在2个或更多的AdRotators中。
让任何特定时间呈现的广告独一无二的最佳方式是什么?一种可能性是将广告分成3个不同的XML文件,并为每个AdRotator分配一个不同的文件。然而,这导致给定的广告总是在相同的位置,可能是,也可能不是页面上的“高级”位置。
发布于 2009-08-30 04:39:45
AdRotator不是为显示一系列横幅而设计的,因此,如果将多个AdRotator控件放在一个窗体上并将它们指向同一个AdvertisementFile,则无法防止重复。
AdRotator仅设计用于提供最基本的广告功能。它绝对不是为了与“真正的”广告服务系统竞争或取代它。如果你需要更详细的东西,你需要研究一下第三方系统或者你自己的系统。
发布于 2011-11-30 02:02:54
尽管我赞同Rex M的建议,即由于其固有的局限性而推出您自己的AdRotator,但在rotator的AdCreatedEvent中有一种方法可以做到这一点。对于3个或更多的旋转者,请尝试http://tinyurl.com/7rymect上概述的概念(必须滚动到页面底部才能看到答案)。否则,您可以尝试在页面上使用2 AdRotators:
/// <summary>
/// First ad rotator control
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void AdRotator_AdCreated(object sender, AdCreatedEventArgs e)
{
//Get displayed ad's id
int currentAd = (int)e.AdProperties["AdId"];
//Remove that ad from the list
TList<Banner> ads = GetBannerThatIsNotThisAdId(currentAd, AdRotator.KeywordFilter);
//Do we have an ad to display?
if (ads.Count > 0)
{
AdRotator1.DataSource = ads;
AdRotator1.DataBind();
}
else //nope, so hide 2nd control
{
AdRotator1.Visible = false;
}
}
public static TList<Banner> GetBannerThatIsNotThisAdId(int adId, string pCategory)
{
BannerService bannerService = new BannerService();
TList<Banner> banners = bannerService.GetAll();
Banner banner = bannerService.GetByAdId(adId);
banners.ApplyFilter(delegate(Banner b) { return b.Keyword.Equals(pCategory) && (b.IsActive.Equals(true)); });
banners.Remove(banner);
return banners;
}https://stackoverflow.com/questions/1353028
复制相似问题