views:

424

answers:

2

I've set up an ASP.NET MVC RC2 application to use a custom controller factory backed by a CommonServiceLocator (using StructureMap). Routing to and instantiating controllers works fine, but for some reason I'm getting exceptions when trying to access .js, .jpg, or any other static file.

Here's the ControllerFactory code:

public class CommonServiceLocatorControllerFactory : DefaultControllerFactory
{
    protected override IController GetControllerInstance(Type controllerType)
    {
        return (controllerType == null) ? 
           base.GetControllerInstance(controllerType) :  
           ServiceLocator.Current.GetInstance(controllerType) as IController;
    }
}

And the exception is:

The controller for path '/someimage.jpg' could not be found or it does not implement IController.

How can I get the factory or routing engine to bypass the controller factory?

Note: I'll be using IIS7/Integrated Mode, but the error occurs with the built in web server for VS2K8.

A: 

I very much doubt this has anything to do with the ControllerFactory. I've just looked at the source code for DefaultControllerFactory.GetControllerInstance, and I can see no means by which this override could cause the error that you are describing. It is probably due to the way you have configured your routes. Take a look at your routing configuration, write unit tests for it, and if you still can't solve the problem, post your routes here.

Craig Stuntz
I'm using the default routes provided with a new project.
mhamrah
A: 

The problem was actually due to 404 errors- the path I was requesting for the static content didn't exist, and the base controller factory couldn't handle the request because there was nothing to deliver.

mhamrah