找不到静态图像的控制器路径? asp.net mvc路由问题?
我有一个图像文件夹存储在 ~/Content/Images/
我通过最近加载这些图像
<img src="/Content/Images/Image.png" />
,图像未加载,并且我在错误日志中收到以下错误。奇怪的是,有些图像可以正常加载,而另一些则无法加载。
有人知道我的路线有什么问题吗?我是否缺少 /Content/ 文件夹的忽略路由?
我对 favicon.ico 和一堆其他图像文件也遇到同样的错误...
<Fatal> -- 3/25/2010 2:32:38 AM -- System.Web.HttpException: The controller for path '/Content/Images/box_bottom.png' could not be found or it does not implement IController.
at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(Type controllerType)
at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName)
at System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext)
at System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext)
at System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
我当前的路线如下所示:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
routes.MapRoute(
"ControllerDefault", // Route name
"{controller}/project/{projectid}/{action}/{searchid}", // URL with parameters
new { controller = "Listen", action = "Index", searchid = "" } // Parameter defaults
);
谢谢!
I have an image folder stored at ~/Content/Images/
I am loading these images via
<img src="/Content/Images/Image.png" />
Recently, the images aren't loading and I am getting the following errors in my error log. What's weird is that some images load fine, while others do not load.
Anyone have any idea what is wrong with my routes? Am I missing an ignore route for the /Content/ folder?
I am also getting the same error for favicon.ico and a bunch of other image files...
<Fatal> -- 3/25/2010 2:32:38 AM -- System.Web.HttpException: The controller for path '/Content/Images/box_bottom.png' could not be found or it does not implement IController.
at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(Type controllerType)
at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName)
at System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext)
at System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext)
at System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
My current routes look like this:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
routes.MapRoute(
"ControllerDefault", // Route name
"{controller}/project/{projectid}/{action}/{searchid}", // URL with parameters
new { controller = "Listen", action = "Index", searchid = "" } // Parameter defaults
);
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我会在第一个路由下方立即插入另一个被忽略的路由。
I would insert another ignored route immediately under the first one.
如果您查看解决方案资源管理器视图,我猜测您的内容文件夹位于项目的根目录中,以及控制器和视图的文件夹。尝试修改您的图像 src,如下所示......
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...
您需要声明到底部的不太具体的路线:
但我不认为这是这里的问题。从异常情况来看,执行此应用程序的 Web 服务器似乎具有与
aspnet_isapi
过滤器的通配符映射,这意味着所有文件都将与 ASP.NET 运行时关联,甚至是静态文件。You need to declare less specific routes to the bottom:
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.你没有
routes.RouteExistingFiles = true;
某处吗?You don't have
routes.RouteExistingFiles = true;
somewhere do you?异常
...无法找到或它没有实现IController
不一定是错误的。实际上/favicon.ico
不会解析为控制器,因此这意味着下一个模块(或者它是处理程序?)应该尝试处理该请求。所以在某种程度上这是一个“预期的例外”。问题是当这个异常被记录并堵塞日志时。使用 log4net 时,将以下
元素添加到默认附加程序应该将其排除在外: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: