What are best practices for implementing Google's hashbang/Ajax crawl pattern with ASP.NET MVC?
http://code.google.com/web/ajaxcrawling/docs/getting-started.html:
the crawler will modify each AJAX URL such as
开发者_如何学Pythonwww.example.com/ajax.html#!key=value
to temporarily become
www.example.com/ajax.html?_escaped_fragment_=key=value
ASP.NET's Routing framework does not allow specifying query string parameters, but of course you can always create an action method that takes _escaped_fragment_ as a parameter (or even just look for the _escaped_fragment_ parameter in the request header).
That's a bit cumbersome however. Is there a better way?
UPDATE:
I went ahead and implemented the following pattern (in my case the fragments look like a regular url path). 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();
}
You write use a custom model binder which 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();
}
精彩评论