1

ASP.NET MVC3 应用程序作为虚拟主机托管在 Mono 中的 Apache 中,地址为http://www.mysite.com

对文件 robots.txt 、 favicon.ico 和 apple-touch-icon.png 的请求会导致以下 404 错误,因为这些名称没有 MVC3 控制器。如何提供这些文件?是否可以强制 Apache 将它们作为常规文件提供服务,或者我们可以强制 MVC3 应用程序返回这些文件?哪个是实现这一点的正确方法?

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 
4

1 回答 1

4

修复 robots.txt:

右键单击项目名称并选择“添加->新建项目”
选择“文本文件”并将其命名为“robots.txt”
您可以将此文件留空

修复 favicon.ico:

转到 Global.asax.cs 文件的 RegisterRoutes 方法并将其添加到顶部附近:您可以查看此页面以获取更多信息:Favicon Icon-MVC3 ASP.NET

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


修复 apple-touch-icon.png:

看看这些网站
为什么我收到 apple-touch-icon-precomposed.png 的错误
http://mathiasbynens.be/notes/touch-icons

于 2013-09-24T17:06:00.843 回答