robots.txt IISExpress dynamic file giving 404

1

I'm using iisexpress with ASP.NET MVC 4 and I've mapped robots.txt to a custom action like so:

        routes.MapRoute("Robots.txt",
            "robots.txt",
            new { controller = "Home", action = "Robots" });

When I set my development server to use IISExpress, i receive the standard IIS 404 error page:

Detailed Error Information:
Module     IIS Web Core
Notification       MapRequestHandler
Handler    StaticFile
Error Code     0x80070002
Requested URL      http://localhost:25315/robots.txt
Physical Path      c:\dev\myapp\myapp\robots.txt
Logon Method       Anonymous
Logon User     Anonymous

When I use Visual Studio Development Server, this seems to work fine and routes correctly.

Is there a particularly web.config or other setting that I need to make to get this to work?

asp.net-mvc
asked on Stack Overflow Nov 24, 2012 by Doug

2 Answers

2

Turns out you need runAllManagedModulesForAllRequests="true" in web.config on modules for this to work in IIS or IIS Express. This is not the default for new asp.net mvc 4 projects

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
    </modules>
  </system.webServer>
answered on Stack Overflow Nov 24, 2012 by Doug
0

Worth checking if your file is not named robots.txt.txt

answered on Stack Overflow Nov 6, 2018 by Kevin Dimey

User contributions licensed under CC BY-SA 3.0