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?
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>
Worth checking if your file is not named robots.txt.txt
User contributions licensed under CC BY-SA 3.0