1

ASP.NET MVC3 application is hosted in Apache in Mono as virtual host with address http://www.mysite.com

Requests for files robots.txt , favicon.ico and apple-touch-icon.png cause 404 error below since there are no MVC3 controllers for those names. How to server those files ? It it possible to force Apache to serve them as regular files or can we force MVC3 application to return those files ? Which is proper way to implement this ?

System.Web.HttpException: The controller for path '/robots.txt' was not found or does not implement IController.
  at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance (System.Web.Routing.RequestContext requestContext, System.Type controllerType) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.DefaultControllerFactory.CreateController (System.Web.Routing.RequestContext requestContext, System.String controllerName) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.MvcHandler.ProcessRequestInit (System.Web.HttpContextBase httpContext, IController& controller, IControllerFactory& factory) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.MvcHandler+<>c__DisplayClass6.<BeginProcessRequest>b__2 () [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.SecurityUtil+<>c__DisplayClassb`1[System.IAsyncResult].<ProcessInApplicationTrust>b__a () [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0 (System.Action f) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust (System.Action action) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust[IAsyncResult] (System.Func`1 func) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.MvcHandler.BeginProcessRequest (System.Web.HttpContextBase httpContext, System.AsyncCallback callback, System.Object state) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.MvcHandler.BeginProcessRequest (System.Web.HttpContext httpContext, System.AsyncCallback callback, System.Object state) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest (System.Web.HttpContext context, System.AsyncCallback cb, System.Object extraData) [0x00000] in <filename unknown>:0 
  at System.Web.HttpApplication+<Pipeline>c__Iterator3.MoveNext () [0x00000] in <filename unknown>:0 
  at System.Web.HttpApplication.Tick () [0x00000] in <filename unknown>:0 
Andrus
  • 26,339
  • 60
  • 204
  • 378

1 Answers1

4

Fixing robots.txt:

Right click the project name and select "Add->New Item"
Choose "Text File" and call it "robots.txt"
You can leave this file blank

Fixing favicon.ico:

Go to the RegisterRoutes method of the Global.asax.cs file and add this near the top: You can look at this page for more info: Favicon Icon-MVC3 ASP.NET

routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });


Fixing apple-touch-icon.png:

Look at these websites
Why am I getting error for apple-touch-icon-precomposed.png
http://mathiasbynens.be/notes/touch-icons

Community
  • 1
  • 1
Andrew
  • 2,013
  • 1
  • 23
  • 38
  • Application can run on different sites having different icons. To resolve favicon issue I added `routes.MapRoute("favicon.ico","favicon.ico",new {controller = "Image", action = "Icon"});` to Global.asax.cs to get icon for specific site. Is this OK ? – Andrus Sep 24 '13 at 19:59
  • I think that should work. If it doesn't, you can add link tags to the view. Here is a stackoverflow post on it: http://stackoverflow.com/questions/487230/serving-favicon-ico-in-asp-net-mvc – Andrew Sep 24 '13 at 20:29
  • Site already has – Andrus Sep 25 '13 at 08:41
  • Is the x-icon and vn.microsoft.icon the only two icons you are trying to load? If so, adding the route I have in my answer (this will ignore any file named favicon.ico) and removing the route you added in the first comment should fix it. – Andrew Sep 25 '13 at 12:30