ASP.NET Adrotatorコントロールページ全体の繰り返し繰り返し

StackOverflow https://stackoverflow.com/questions/2838409

  •  26-09-2019
  •  | 
  •  

質問

ダイナミックな長さのページの長さを繰り返す広告を繰り返す必要があるWebサイトを作成しています。ページの全長に広告を表示したいのですが、データが表示されるまでその長さはわかりません。 .NETにこれの機能が組み込まれていますか?そうでない場合、誰かが私のためにこれを行うために採用できる回避策を見ていますか?

ありがとう!

役に立ちましたか?

解決

ページがエンドユーザーのブラウザでレンダリングされた後に(AJAX経由で)サーバーに電話をかけて広告を取得することで、この問題を最適に解決すると思います。

これは、快適さに応じて、いくつかのテクノロジー(ajax.netとupdatepanels、plain-old-javascript、またはjqueryやmootoolsのようなWebサービスなどのJSフレームワーク)を介して行うことができます。

jquery + ashxオプションを使用すると、次のことを行うことができます。

JavaScriptで:

// when the document has finished loading
$(document).load(function() {

    // make an AJAX request to MyHandler.ashx, with the content's height
    var height = $("#ContentContainer").height()
    $.get("MyHandler.ashx?contentheight=" + height, ResponseCallback);
}

// put the server's response (data) into the ad container
function ResponseCallback(data) {
    $("#AdContainer").html(data);
}

HTMLで:

<body>
  <div id="ContentContainer">
     ... 
     ...
  </div>
  <div id="AdContainer"></div>
</body>

myhandler.ashx:

public void ProcessRequest(HttpContext context) {
    HttpRequest request = context.Request;
    HttpResponse response = context.Response;

    int height = Convert.ToInt32(request.QueryString["contentheight"] ?? "0");

    // do something to calculate number of ads and get the HTML for the ads
    // assuming we have a list of Advert objects:
    List<Advert> ads = GetSomeAds(height);

    foreach(Advert a in ads) {
        response.Write(a.GetHtml());
    }
}

明らかにASP.NETと最も統合されているのはUpdatePanelオプションですが、サーバー側に.Ashx(カスタムハンドラー)または.asmx(Webサービス)を使用してJSフレームワークを使用することをお勧めします。 「このコードは何をしているのか」を知っているという点で、それははるかに透明で理解できます。 UpdatePanelsは黒魔術のように見えることがあります。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top