views:

30

answers:

1

I have 2 master pages. One is intended to be shown in a normal standalone website. The other is to be used in external sites as an Iframe.

I want to be able to show the normal page at http://example.com/home/index and the iframed version at http://example.com/framed/home/index

I want to have controls that will postback to one controller so I don't have to duplicate logic, so they must be available in both the normal and iframed versions.

My problem is that when I try and use areas, I just can't get them to work right with the default url. Also, I have the added complication of structuremap. When I try and hit /area/controller/action, I get

The IControllerFactory 'MySite.Web.Code.IoC.StructureMapControllerFactory' did not return a controller for the name 'MyArea'.

Does anyone know how to make this kind of setup work? Really all I'm doing is trying to show one set of views if it has /Framed/controller/action and another set if it does not have /framed. I thought areas were the way to go, but maybe not.

+1  A: 

All of our controllers implement the same base class, and we use the following override to do what you're describing:

protected override ViewResult View(string viewName, string masterName, object model)
{
    if (masterName == null)
    {
        var options = PortalRequestManager.CurrentPortalRouteOptions;
        masterName = options.MvcMasterPath;
    }
    return base.View(viewName, masterName, model);
}

All of our AreaRegistrations use the following method to register their areas:

    public static void RegisterMvcAreaRoutes(AreaRegistrationContext context, string name, string url,
                                             object defaults)
    {
        context.MapRoute(name + "Portal",
                         "P/Channel/" + url,
                         defaults);
        context.MapRoute(name + "FramePortal",
                         "F/Channel/" + url,
                         defaults);
    }

And then the PortalRequestManager that you saw in the first code block parses the URL to see if it uses "/P" or "/F" to determine which MvcMasterPath to use.

We use Ninject's controller factory, which has no problem with this setup, so I can't really speak to your problems with StructureMap.

StriplingWarrior
My problem is that the /P and /F in your case are treated like controllers, no matter how I do my routing, and then null is passed into my controller factory for controllerType.
Josh
I wonder if you have a routing defined somewhere that's overriding the other routes? For example, if your Global.asax.cs file maps a route to `{controller}/{action}/{id}`, then this would conflict with other routes that begin with something other than controller. In our case, *all* of our routes begin with "F" or "P", so there is no conflict. Search your code for references to `MapRoute` and make sure there are no interfering routes being registered.
StriplingWarrior
I did something similar to get it work. http://stackoverflow.com/questions/3943556/mvc-2-0-structuremap-areas-and-duplicate-controller-names
Josh