Osk*_*ard 7 ajax asp.net-mvc search routing
使用ASP.NET MVC实现Google的hashbang/Ajax爬网模式的最佳实践是什么?
http://code.google.com/web/ajaxcrawling/docs/getting-started.html:
爬虫将修改每个AJAX URL,例如
Run Code Online (Sandbox Code Playgroud)www.example.com/ajax.html#!key=value暂时成为
Run Code Online (Sandbox Code Playgroud)www.example.com/ajax.html?_escaped_fragment_=key=value
ASP.NET的路由框架不允许指定查询字符串参数,但当然您总是可以创建一个将_escaped_fragment_作为参数的操作方法(甚至只需在请求标头中查找_escaped_fragment_参数).
然而,这有点麻烦.有没有更好的办法?
更新:
我继续并实现了以下模式(在我的例子中,片段看起来像一个常规的url路径).同样,这不是最干净的方法,所以欢迎任何建议.
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();
}
Run Code Online (Sandbox Code Playgroud)
您编写使用自定义模型绑定器,它将采用_escaped_fragment_查询字符串参数并返回一些强类型模型:
public ActionResult Index(MyModel model)
{
// Directly use model.Id, model.Key1, model.Key2, ...
return View();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2689 次 |
| 最近记录: |