gpt4 book ai didi

asp.net-mvc - 使用 ASP.NET MVC 实现 Google 的 hashbang/Ajax 抓取?

转载 作者:行者123 更新时间:2023-12-04 12:56:11 25 4
gpt4 key购买 nike

使用 ASP.NET MVC 实现 Google 的 hashbang/Ajax 抓取模式的最佳实践是什么?

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

the crawler will modify each AJAX URL such as

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

to temporarily become

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


ASP.NET 的路由框架不允许指定查询字符串参数,但当然您始终可以创建一个将 _escaped_fragment_ 作为参数的操作方法(或者甚至只是在请求 header 中查找 _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();
}

最佳答案

您编写使用自定义模型绑定(bind)器,它将采用 _escaped_fragment_查询字符串参数并返回一些强类型模型:

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

关于asp.net-mvc - 使用 ASP.NET MVC 实现 Google 的 hashbang/Ajax 抓取?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5643257/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com