我有一个不是静态的robots.txt,而是动态生成的。我的问题是创建从root/robots.txt到我的 Controller 操作的路由。
这个是的作品:
routes.MapRoute(
name: "Robots",
url: "robots",
defaults: new { controller = "Home", action = "Robots" });
这个不起作用:
routes.MapRoute(
name: "Robots",
url: "robots.txt", /* this is the only thing I've changed */
defaults: new { controller = "Home", action = "Robots" });
“.txt”导致ASP明显拒绝
最佳答案
您需要将以下内容添加到web.config文件中,以允许执行带有文件扩展名的路由。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!-- ...Omitted -->
<system.webServer>
<!-- ...Omitted -->
<handlers>
<!-- ...Omitted -->
<add name="RobotsText"
path="robots.txt"
verb="GET"
type="System.Web.Handlers.TransferRequestHandler"
preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
</configuration>
有关更多详细信息,请参见我在Dynamically Generating Robots.txt Using ASP.NET MVC上的博客文章。
关于asp.net-mvc - 如何在ASP.NET MVC中添加到动态robots.txt的路由?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17160744/