Quantcast
Viewing latest article 11
Browse Latest Browse All 15

Controller IControllerFactory could not create a controller for controller name 'Content'.

I got this error when I tried to run this code in my view.

<img src='<%= Url.Content("~/Content/Images/logo.gif") %>' />

At first I didn't realize the underlying issue but then quickly realized that when the MVC framework can't find a resource available on disk, it attempts to serve up the resource using a controller.  My folder structure actually had changed during the project and no the logo resided in Content/Images/Framework, but the URL was using the old directory.

When it can't find the file being accessed, the framework attempts to route the file through the route table established on the global.asax, which is exactly what it was trying to do; it was looking for a controller with the name ContentController, with an Images action method.  And since that can't be found, nothing gets returned.

The RouteTable.Routes property (of RouteCollection type) returns a RouteExistingFiles property.  The default value is false, meaning files on disk do not go through the routing process.  If you set this value to true, existing file routes go through the routing process, which requires a controller.

Image may be NSFW.
Clik here to view.

Viewing latest article 11
Browse Latest Browse All 15

Trending Articles