【发布时间】:2015-08-15 05:05:51
【问题描述】:
我已经阅读了一篇关于在我的 ASP MVC.NET 项目中从某个 url 忽略机器人的文章。在他的文章中作者说我们应该像这样在一些关闭控制器中添加一些动作。在此示例中,他将操作添加到 Home Controller:
#region -- Robots() Method --
public ActionResult Robots()
{
Response.ContentType = "text/plain";
return View();
}
#endregion
那么我们应该在我们的项目中添加一个带有这个body的Robots.cshtml文件
@{
Layout = null;
}
# robots.txt for @this.Request.Url.Host
User-agent: *
Disallow: /Administration/
Disallow: /Account/
最后我们应该将这行代码添加到Gloabal.asax
routes.MapRoute("Robots.txt",
"robots.txt",
new { controller = "Home", action = "Robots" });
我的问题是机器人是否会抓取具有 [Authorization] 属性的控制器,例如Administration?
【问题讨论】:
-
对于那些尝试使用上述代码的人:它可以工作,但您必须激活路径“robots.txt”由您的 web.conf 中的 MVC 路由处理,请参阅:@987654321 @
标签: asp.net asp.net-mvc-4 seo robots.txt