Creating an Html Snapshot using phantomjs
and google will replace the #! with "?_escaped_fragment_=" and send the following request to your server
Doing this allows your server to see the client url and respond accordingly.
Show me the code!
This code which is taken from the Startup.cs class used for configuring Owin adds a piece of middleware which inspects all requests and sends the request to PhantomJS if the request is coming from a bot. I haven't used this in any production environment but I am using that on this site to make it so that I can share posts and have them indexed. In my testing PhantomJS takes about .5 seconds to render this site which is completely rendered in the browser using AngularJS. I have set up caching for use with this site where I push the generated html to mongo so that I only pay the price to render the content for bots once.
app.Use((context, next) =>
if (context.Request.QueryString.HasValue && context.Request.QueryString.Value.StartsWith("_escaped_fragment_="))
var actualUrl = context.Request.Uri.AbsoluteUri.Replace("?_escaped_fragment_=", "#!");
var driver = new OpenQA.Selenium.PhantomJS.PhantomJSDriver();
var cachedContent = driver.PageSource;
context.Response.StatusCode = 200;
context.Response.ContentType = "text/html";
DetailsThis should work in any ASP.NET site but I have only tested it here on my blog which is only using Web.API and not MVC or WebForms, also
to get the above snippet to work you will also need to add the "Selenium.Webdriver" and "phantomjs.exe" Nuget packages to your project.