Implementing a Google hashbang / Ajax workaround with ASP.NET MVC?

What are the best methods for implementing a Google hashbang / Ajax crawl pattern using ASP.NET MVC?

http://code.google.com/web/ajaxcrawling/docs/getting-started.html :

the crawler will change every AJAX URL such as

www.example.com/ajax.html#!key=value 

to temporarily become

 www.example.com/ajax.html?_escaped_fragment_=key=value 

The ASP.NET routing structure does not allow you to specify query string parameters, but of course you can always create an action method that takes _escaped_fragment_ as a parameter (or even just searches for the _escaped_fragment_ parameter in the request header).

This is a little cumbersome. Is there a better way?

UPDATE:

I went ahead and implemented the following pattern (in my case, the fragments look like a regular URL). Again, this is hardly the cleanest approach, so any suggestions are welcome.

 public virtual ActionResult Index(int id, string _escaped_fragment_) { //Handle Google Ajax Crawler if (_escaped_fragment_ != null) { string[] fragments = _escaped_fragment_.Split(new char[]{'/'}, StringSplitOptions.RemoveEmptyEntries); if (fragments.Length > 0) { //parse fragments //return static content } } //normal action operation return View(); } 
+7
source share
1 answer

You are writing using a custom binder that will take the _escaped_fragment_ query string parameter and return some strongly typed model:

 public ActionResult Index(MyModel model) { // Directly use model.Id, model.Key1, model.Key2, ... return View(); } 
+1
source

All Articles