admin管理员组

文章数量:1287800

Update

Ok - I now know where the multiple page loads are ing from! (However, the mystery is not yet solved).

It seems that immediately after a request is made to a page containing AdSense ads, Google makes a request for exactly the same URL (one or more times)

e.g. this is what the logs look like (note requests from Mediapartners-Google):

2011-07-20 09:50:20 xxx.xxx.xxx.xxx GET /requestedURL/ 80 - xxx.xxx.xxx.xxx Mozilla/5.0+(Browserstring removed) 200 0 0 1140
2011-07-20 09:50:20 xxx.xxx.xxx.xxx GET /requestedURL/ 80 - 66.249.72.52 Mediapartners-Google 200 0 64 218
2011-07-20 09:50:22 xxx.xxx.xxx.xxx GET /requestedURL/ 80 - 66.249.72.52 Mediapartners-Google 200 0 0 171

(I should have paid more attention to the IIS logs, rather than my own application logs - it just didn't occur to me that these multiple, identical, simultaneous request could have been ing from different sources). This also explains why I couldn't find anything strange when analysing the request with WireShark, and why fiddler didn't show anything strange.

So the question for the bounty now bees:

  • Why is google making these requests so quickly after the page is requested? (I know they need to asses the page for content, but immediately after, and multiple times sees like abuse to me.)
  • What can I do to stop this?

And out of interest:

  • Has anyone else seem something similar in their logs? (or is this something weird with my AdSense account)

Ok, I'll apologise in advance for the length!...

This question is realted to this one, regarding Google Adsense Javascript code causing errors. (of the form Unable to post message to googleads.g.doubleclick. Recipient has origin something)

I won't duplicate all of the information there, but the conclusion seems to be that the AdSense JS is buggy. (please read the question for background if you have time). I knew about this problem for some time, but decided to live with the JS errors rather than pulling AdSense from the site.

However, Recently I noticed that in my ASP.NET MVC2 application, Controller Actions seemed to be called twice per page request (sometimes even 3 times). Odly, it was only happening on the production server. After some thought I relalised that one difference between the Dev and Production environments was that the AdSense javscript was only active in production.

To test this I removed all adsense code from one of the production pages, and lone behold, the multiple-page-load problem went away!

I thought that perhaps it was the fact that there were general JS errors on the page that was causing the problem, so to test this I introduced some simple errors into my own JS code, however this did not cause the multiple-page-load problem to reappear.

One known situation where pages can be called multiple times per request is when there are image tags with empty src attributes, or external resource references with empty src attributes. Crucially, The most upvoted answer to the AdSense JS Bug question notes that:

"The targetOrigin argument in this call, this.la is set to . However, the new iframe was written with its src set to about:blank."

This seems eerily similar to the empty src issue.... This seems too much of a co-incidence, and currently I'm of the opinion that this is the problem. [EDIT: This was a red herring]

However, I've no idea wehre to go from here. These multiple action calls are causing real problems (I'm having to use code blocking, serialised transactions, and all sorts of nasty hacks to limit adverse effects). Of course, I could be barking up the wrong tree entirely - I'm puzzled that I can't find any other references to this, given the ubiquity of AdSense, and the nature of the problem (but then again the conclusions of the AdSense JS Bug question are also surprising). I would love this to turn out to be a stupid mistake on my part, so I need a sanity check.

I'd like to ask the munity:

  • Has anyone else experienced this problem?, or can anyone who is using AdSense replicate and confirm it? [See note below]
  • Assuming the problem is what it seems, what can I do? (other than pulling AdSense of course)
  • If not, then what might be causing this?

To Sumarise: - My actions are being executed 2 (sometimes 3) times per page request.

  • THIS ONLY HAPPENS WHEN GOOGLE ADSENSE ADS ARE PRESENT
  • I removed all AdSense JS and introduced an error into my own JS : Actions are called only once...
  • A similar problem can happen when empty src properties are present on the page
  • An answer to a previous question sumarises that the AdSense JS sets a src="about:blank" on an iFrame
  • I have e to the conclusion that the src="about:blank" from the AdSense code is the most likely source of the problem.
  • If I disable JavaScript on the browser, the problem goes away

Just to document the things I have ruled out:

  • This is happening across browsers: Chrome(12) Firefox(5) and IE(8).
  • I have dissabled all plugins on browsers (YSlow, Firebug etc...)
  • There are no empty src (src=""/src="#") for images, or other external resources in the html in my code
  • There are no empty url references in the css ( url('') )
  • It's unlikely to be server side code/config problem, as it doesn't happen in Dev (and of the few differences between dev and production is the absence of AdSence JS in Dev)

Note: For anyone looking to replicate this, it should be noted that, strangely, when the multiple action calls happen Fiddler shows only one request being sent to the server. I have no idea why this should be the case, but the server logging doesn't lie :) Perhaps someone who has prior experience with this problem when caused by empty src attributes in img tags can say whether they have seen the same behaviour with Fiddler.


Requested extra information

HTML (@Ivan)

Here's how I'm implementing the Adsense (ids removed)

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<div class="ad">
<%if (!HttpContext.Current.IsDebuggingEnabled) { %>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-xxxxxxxxxxxxxxx";
/* xxxxxxxxxxxxxxx */
google_ad_slot = "xxxxxxxxx";
google_ad_width = 728;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript" src=".js">
</script>                     
<%} else { %>
<img src="/Content/images/googleAdMock728x15_4_e.gif" width="728" height="15" />
<%} %>
</div>

This is being inserted by a RenderPartial in the View:

<% Html.RenderPartial("AdSense_XXXXXX"); %>

TCP Logging (@Tomas)

So far I have done a wireshark capture:

  1. on client when requesting page on production with problem
  2. on client when requesting page on production without problem (i.e. Adsense Removed)

I can't really see a significant difference between the two (although my network skills are not great). One thing to note is that they both seem to have a TCP retransmittion of the HTTP request immediately after the initial request - I don't know the significance of that. I can confirm though that in case 1 the server logs reported 2 executions, and in case 2 only one execution.

Next I will try TCP logging on the server side in both cases, and post results here.

Update

Ok - I now know where the multiple page loads are ing from! (However, the mystery is not yet solved).

It seems that immediately after a request is made to a page containing AdSense ads, Google makes a request for exactly the same URL (one or more times)

e.g. this is what the logs look like (note requests from Mediapartners-Google):

2011-07-20 09:50:20 xxx.xxx.xxx.xxx GET /requestedURL/ 80 - xxx.xxx.xxx.xxx Mozilla/5.0+(Browserstring removed) 200 0 0 1140
2011-07-20 09:50:20 xxx.xxx.xxx.xxx GET /requestedURL/ 80 - 66.249.72.52 Mediapartners-Google 200 0 64 218
2011-07-20 09:50:22 xxx.xxx.xxx.xxx GET /requestedURL/ 80 - 66.249.72.52 Mediapartners-Google 200 0 0 171

(I should have paid more attention to the IIS logs, rather than my own application logs - it just didn't occur to me that these multiple, identical, simultaneous request could have been ing from different sources). This also explains why I couldn't find anything strange when analysing the request with WireShark, and why fiddler didn't show anything strange.

So the question for the bounty now bees:

  • Why is google making these requests so quickly after the page is requested? (I know they need to asses the page for content, but immediately after, and multiple times sees like abuse to me.)
  • What can I do to stop this?

And out of interest:

  • Has anyone else seem something similar in their logs? (or is this something weird with my AdSense account)

Ok, I'll apologise in advance for the length!...

This question is realted to this one, regarding Google Adsense Javascript code causing errors. (of the form Unable to post message to googleads.g.doubleclick. Recipient has origin something.)

I won't duplicate all of the information there, but the conclusion seems to be that the AdSense JS is buggy. (please read the question for background if you have time). I knew about this problem for some time, but decided to live with the JS errors rather than pulling AdSense from the site.

However, Recently I noticed that in my ASP.NET MVC2 application, Controller Actions seemed to be called twice per page request (sometimes even 3 times). Odly, it was only happening on the production server. After some thought I relalised that one difference between the Dev and Production environments was that the AdSense javscript was only active in production.

To test this I removed all adsense code from one of the production pages, and lone behold, the multiple-page-load problem went away!

I thought that perhaps it was the fact that there were general JS errors on the page that was causing the problem, so to test this I introduced some simple errors into my own JS code, however this did not cause the multiple-page-load problem to reappear.

One known situation where pages can be called multiple times per request is when there are image tags with empty src attributes, or external resource references with empty src attributes. Crucially, The most upvoted answer to the AdSense JS Bug question notes that:

"The targetOrigin argument in this call, this.la is set to http://googleads.g.doubleclick. However, the new iframe was written with its src set to about:blank."

This seems eerily similar to the empty src issue.... This seems too much of a co-incidence, and currently I'm of the opinion that this is the problem. [EDIT: This was a red herring]

However, I've no idea wehre to go from here. These multiple action calls are causing real problems (I'm having to use code blocking, serialised transactions, and all sorts of nasty hacks to limit adverse effects). Of course, I could be barking up the wrong tree entirely - I'm puzzled that I can't find any other references to this, given the ubiquity of AdSense, and the nature of the problem (but then again the conclusions of the AdSense JS Bug question are also surprising). I would love this to turn out to be a stupid mistake on my part, so I need a sanity check.

I'd like to ask the munity:

  • Has anyone else experienced this problem?, or can anyone who is using AdSense replicate and confirm it? [See note below]
  • Assuming the problem is what it seems, what can I do? (other than pulling AdSense of course)
  • If not, then what might be causing this?

To Sumarise: - My actions are being executed 2 (sometimes 3) times per page request.

  • THIS ONLY HAPPENS WHEN GOOGLE ADSENSE ADS ARE PRESENT
  • I removed all AdSense JS and introduced an error into my own JS : Actions are called only once...
  • A similar problem can happen when empty src properties are present on the page
  • An answer to a previous question sumarises that the AdSense JS sets a src="about:blank" on an iFrame
  • I have e to the conclusion that the src="about:blank" from the AdSense code is the most likely source of the problem.
  • If I disable JavaScript on the browser, the problem goes away

Just to document the things I have ruled out:

  • This is happening across browsers: Chrome(12) Firefox(5) and IE(8).
  • I have dissabled all plugins on browsers (YSlow, Firebug etc...)
  • There are no empty src (src=""/src="#") for images, or other external resources in the html in my code
  • There are no empty url references in the css ( url('') )
  • It's unlikely to be server side code/config problem, as it doesn't happen in Dev (and of the few differences between dev and production is the absence of AdSence JS in Dev)

Note: For anyone looking to replicate this, it should be noted that, strangely, when the multiple action calls happen Fiddler shows only one request being sent to the server. I have no idea why this should be the case, but the server logging doesn't lie :) Perhaps someone who has prior experience with this problem when caused by empty src attributes in img tags can say whether they have seen the same behaviour with Fiddler.


Requested extra information

HTML (@Ivan)

Here's how I'm implementing the Adsense (ids removed)

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<div class="ad">
<%if (!HttpContext.Current.IsDebuggingEnabled) { %>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-xxxxxxxxxxxxxxx";
/* xxxxxxxxxxxxxxx */
google_ad_slot = "xxxxxxxxx";
google_ad_width = 728;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication./pagead/show_ads.js">
</script>                     
<%} else { %>
<img src="/Content/images/googleAdMock728x15_4_e.gif" width="728" height="15" />
<%} %>
</div>

This is being inserted by a RenderPartial in the View:

<% Html.RenderPartial("AdSense_XXXXXX"); %>

TCP Logging (@Tomas)

So far I have done a wireshark capture:

  1. on client when requesting page on production with problem
  2. on client when requesting page on production without problem (i.e. Adsense Removed)

I can't really see a significant difference between the two (although my network skills are not great). One thing to note is that they both seem to have a TCP retransmittion of the HTTP request immediately after the initial request - I don't know the significance of that. I can confirm though that in case 1 the server logs reported 2 executions, and in case 2 only one execution.

Next I will try TCP logging on the server side in both cases, and post results here.

Share Improve this question edited May 23, 2017 at 12:09 munity wiki
17 revs
UpTheCreek 9
  • Since you have conflicting data between the web server log and fiddler, have you tried running tcp level logging on both client and server ( both dev and prod ) wireshark is excelent for this if somewhat verbose – Tomas Commented Jul 18, 2011 at 8:01
  • Hi Tomas, You're right - I should do that. I'll run the test later today and post the results in the question. Thanks. – UpTheCreek Commented Jul 18, 2011 at 8:57
  • Very good! It's best to run the captures on both client and server at the same time to help eliminate false positive package drop/ resend due to tcp/ip offloading. In some scenarios behavior close to what you described may occur. – Tomas Commented Jul 18, 2011 at 9:59
  • Can you post the HTML (or at least the relevant portion) of the page that is doing this behavior? – Ivan Commented Jul 19, 2011 at 0:13
  • @Ivan - the relevant portion is just the standard Google AdSense JS. – UpTheCreek Commented Jul 19, 2011 at 8:05
 |  Show 4 more ments

4 Answers 4

Reset to default 4

Mediabot is the name given to the web crawler that Google uses to crawl webpages for purposes of analysing the content so Google AdSense can serve contextually relevant advertising to the page.

In my experience, it is impredictable and, yes , it can be pretty heavy and annoying.

If you don't want Mediapartner bot to access a specific page, you can disallow it in your robots.txt with:

#
# disallow adsense bot
#
User-agent: Mediapartners-Google
Disallow: path to your specific page

This will have the drawback of service untargeted ads from that specific page.

If you are seeing this pattern always on the same page with different query string, adding the canonical rel could ease the pain.

If you can't resolve this issue, and you see it as an abuse, don't esitate to ask help in the Crawling Indexing and Ranking Google support.

Given that the behaviour that you are observing appear to be hard to avoid, can we rather focus on workarounds?

Can you differentiate requests based on UserAgent, and thus filter out requests. Could that be a viable approach for you? If so then you could probably base upon this approach: http://blog.flipbit.co.uk/2009/07/writing-iphone-sites-with-aspnet-mvc.html Here they detect iPhones, but the consept is the same for Mediapartners-Google bot.

Aside from the embedding of the AdSense code itself, there are two things related to AdSense that differ in your two test cases:

  1. What else happens when !HttpContext.Current.IsDebuggingEnabled? This appears to be the de-facto production flag; maybe there is some other nuance somewhere that is happening that depends on this same flag.

  2. Is it possible that Html.RenderPartial("AdSense_XXXXXX") is somehow causing your Controller to jump back to the beginning of its execution?

From your description, it seems like the execution is happening twice on the server but only one request is being sent from the client. This implies a server error, and these two lines are the crux of your AdSense triggering. To further narrow it down, try embedding the AdSense partial directly instead of calling Html.RenderPartial(). If that doesn't change the result, it might be worth a sanity check on what else switches on HttpContext.Current.IsDebuggingEnabled.

Failing that, it might be helpful to know whether your server-side logging takes place as the request is received, before the response is sent, or after the response is sent.

Yes, I just detected this during a TeamView session with my partner. On my box my main page ONLY for my site loads once per request.

Then by coincidence while using Fiddler my partner is getting 4 requests to the sample page. It is a 1.5 MB page with big scripts and lotsa other dependencies so this was truly a WTF moment as I have never seen anything like this in 15 years of web development.

If google is doing this I must say they should realize today's sites might have very big pages and very big audiences. That could mean they are jacking bandwidth by a factor of 4 per request. Like I said, WTF?????

I wish this Q&A had a more definitive resolution. I do use Google Translate widget but this is only occurring on his box and for the main page. The other pages also use the translate widget and I do request my JQUERY via the google CDN. Could anything Google be doing this.

本文标签: aspnet mvcGoogle AdSense JavaScript causing multiple pageloadsStack Overflow