controller path not found for static images? asp.net mvc routing issue?

試著忘記壹切 提交于 2019-12-04 23:30:23

I would insert another ignored route immediately under the first one.

routes.IgnoreRoute("Content/Images/{*pathInfo}");

If you look at your solution explorer view, I'm guessing that your Content folder is in the root of the project along with a folder for Controllers and Views. Trying modifying your image src as shown below...

<img src="../../Content/Images/Image.png" />
ScottG
<img src="<%= Url.Content("~/Content/Images/Image.png")%>" alt="does this work?" />

You need to declare less specific routes to the bottom:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
    "ControllerDefault",
    "{controller}/project/{projectid}/{action}/{searchid}",
    new { controller = "Listen", action = "Index", searchid = "" }
);

routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = "" }
);

But I don't think that this is the problem here. From the exception it seems that the web server executing this application has a wildcard mapping with the aspnet_isapi filter meaning that all file will be associated with the ASP.NET runtime even the static files.

You don't have routes.RouteExistingFiles = true; somewhere do you?

The exception ... could not be found or it does not implement IController doesn't have to be in error. Actually /favicon.ico doesnt resolve to a controller so this means that the next module (or is it handler?) should try to handle the request. So in a way it's an "expected exception".

The problem is when this exception gets logged and clogs the logs. When using log4net, adding the following <filter> element to the default appender should keep it out:

<filter type="log4net.Filter.StringMatchFilter">
  <regexToMatch value="System.Web.HttpException \(0x80004005\): The controller for path '[^']*' was not found or does not implement IController\." />
  <acceptOnMatch value="false" />
</filter>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!