Asp.net-ad-rotator
ASP.NET-広告ローテーター
AdRotatorコントロールは、外部XMLスケジュールファイルで指定されたリストからバナーグラフィックをランダムに選択します。 この外部XMLスケジュールファイルは、広告ファイルと呼ばれます。
AdRotatorコントロールを使用すると、AdvertisementFileプロパティとTargetプロパティで、リンクが従うべき広告ファイルとウィンドウのタイプをそれぞれ指定できます。
AdRotatorを追加する基本的な構文は次のとおりです。
AdRotatorコントロールとそのプロパティの詳細を説明する前に、広告ファイルの構築について見てみましょう。
広告ファイル
広告ファイルはXMLファイルであり、表示される広告に関する情報が含まれています。
拡張マークアップ言語(XML)は、テキストドキュメントマークアップのW3C標準です。 これは、意味のあるタグを使用して、構造化された形式でデータを保存できるテキストベースのマークアップ言語です。 「拡張可能」という用語は、アプリケーションに意味のあるタグを定義することにより、ドキュメントを記述する能力を拡張できることを意味します。
XMLは、HTMLのような言語そのものではなく、新しいマークアップ言語を作成するための一連のルールです。 これはメタマークアップ言語です。 開発者は、特別な用途のカスタムタグセットを作成できます。 情報を構造化、保存、および転送します。
以下はXMLファイルの例です。
すべてのXMLファイルと同様に、広告ファイルは、データを記述する明確に定義されたタグを持つ構造化テキストファイルである必要があります。 広告ファイルで一般的に使用される次の標準XML要素があります。
Element | Description |
---|---|
Advertisements | Encloses the advertisement file. |
Ad | Delineates separate ad. |
ImageUrl | The path of image that will be displayed. |
NavigateUrl | The link that will be followed when the user clicks the ad. |
AlternateText | The text that will be displayed instead of the picture if it cannot be displayed. |
Keyword | Keyword identifying a group of advertisements. This is used for filtering. |
Impressions | The number indicating how often an advertisement will appear. |
Height | Height of the image to be displayed. |
Width | Width of the image to be displayed. |
これらのタグとは別に、カスタム属性を持つカスタムタグも含めることができます。 次のコードは、広告ファイルads.xmlを示しています。
AdRotatorクラスのプロパティとイベント
AdRotatorクラスはWebControlクラスから派生し、そのプロパティを継承します。 これらとは別に、AdRotatorクラスには次のプロパティがあります。
Properties | Description |
---|---|
AdvertisementFile | The path to the advertisement file. |
AlternateTextFeild | The element name of the field where alternate text is provided. The default value is AlternateText. |
DataMember | The name of the specific list of data to be bound when advertisement file is not used. |
DataSource | Control from where it would retrieve data. |
DataSourceID | Id of the control from where it would retrieve data. |
Font | Specifies the font properties associated with the advertisement banner control. |
ImageUrlField | The element name of the field where the URL for the image is provided. The default value is ImageUrl. |
KeywordFilter | For displaying the keyword based ads only. |
NavigateUrlField | The element name of the field where the URL to navigate to is provided. The default value is NavigateUrl. |
Target | The browser window or frame that displays the content of the page linked. |
UniqueID | Obtains the unique, hierarchically qualified identifier for the AdRotator control. |
AdRotatorクラスの重要なイベントは次のとおりです。
Events | Description |
---|---|
AdCreated | It is raised once per round trip to the server after creation of the control, but before the page is rendered |
DataBinding | Occurs when the server control binds to a data source. |
DataBound | Occurs after the server control binds to a data source. |
Disposed | Occurs when a server control is released from memory, which is the last stage of the server control lifecycle when an ASP.NET page is requested |
Init | Occurs when the server control is initialized, which is the first step in its lifecycle. |
Load | Occurs when the server control is loaded into the Page object. |
PreRender | Occurs after the Control object is loaded but prior to rendering. |
Unload | Occurs when the server control is unloaded from memory. |
AdRotatorコントロールの使用
新しいWebページを作成し、その上にAdRotatorコントロールを配置します。
ads.xmlファイルと画像ファイルは、Webサイトのルートディレクトリに配置する必要があります。
上記のアプリケーションを実行して、ページがリロードされるたびに広告が変更されることを確認してください。