greengerong / Prerender_asp_mvc

Prerende client for asp.net mvc
http://prerender.io/
86 stars 39 forks source link

Fix prerender server returning status other than 200, which caused the m... #3

Closed mgoodfellow closed 10 years ago

mgoodfellow commented 10 years ago

...iddleware to bomb out, and the normal request pipeline continued. Now the WebException is handled and the correct status code (such as 404 etc.) is passed to the client along with the prerendered content from the server

greengerong commented 10 years ago

Thanks @mgoodfellow . I think i would like to when the prender server throw exception, we can response the really html page(with javascript stuffs).

but so far i am on a business trip, I do not have the .net env.

try{ if(shouldDoPrerender(XXX)){ .............................. } }

mgoodfellow commented 10 years ago

Hi @greengerong,

Unfortunately I believe that this behaviour goes against what prerender is trying to accomplish.

Consider the following:

1) Google crawls a page on the site:

GET www.some-website.com/non-existing-page

2) This page doesn't exist and the AngularJS (or other framework) sets the meta tag to tell the prerender server to return a 404 error.

<meta name="prerender-status-code" content="404">

3) The ASP.NET middleware should now handle that 404 (which is returned as a WebException) and pass it onto the crawler.

In the original implementation you describe, the ASP.NET middleware hides the exception and the normal request pipeline is resuming, which in turn means we instead return a 200 to the crawler along with a bunch of JavaScript that it does not run, and the crawler is misled.

Kind regards,

Mike