views:

675

answers:

2

I'm attempting to create an MVC application as a sub-application to my standard Asp.Net Web application. Both of these projects are inside the same solution. While the parent application appears to be going fine, I'm having trouble getting the sub-application to work. After some massaging of my two web.configs, I was able to get the Asp.Net runtime to accept the configurations, but I have been unable to browse to any of the pages/controllers in the MVC application, including the root of the sub-application ("http://RootSite/SubApplicationName/"). I continually get 404's.

Actually, I do get a response when going to the url "http://RootSite/SubApplicationName/Home/Index/". It redirects me to index.aspx in that folder, and throws this error:

The view 'Index' or its master could not be found. The following locations were searched:
~/Views/Home/Index.aspx
~/Views/Home/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx

The sub-application in IIS (7) is set up fairly straight forward: it's set to run in the same application pool as the parent app, which runs Asp.Net 2.0 in integration mode.

My suspicion is that I have something in the web.configs that is throwing it off. Are there things regarding, say, HTTPModules or URL authorization modules, etc., that I should confirm aren't getting in the way of MVC?

Also, in the global.asax.cs file, should the default route be different? By default, the url parameter passed to routes.MapRoute is:

"{controller}/{action}/{id}"

Should it be preceded by the name of the sub-application, like so?

"SubApplicationName/{controller}/{action}/{id}"

I attempted a change like that, but it did not fix things.

Any ideas are much appreciated. Also, general information about setting up an MVC web application as a sub-application would be great.

Thanks.

+1  A: 

Hi, I did something similar, however not the same, I had to load views from a separate dll. In my case it was a class library, not a different web app, but it should work the same as far as I know.

The first thing you have to do is to create a VirtualPath Provider to tell the routing engine how to look for your stuff in the subapplication views. A great explanation of how to do this can be found here:

http://www.wynia.org/wordpress/2008/12/05/aspnet-mvc-plugins/

I'm sure that will get you started ;)

antonioh
Thank you! I will read that and let you know if it worked for me.
Moskie
It looks a bit tricky at first but that post is quality and you can download the Visual Studio solution of it so you will be able to play around ;)
antonioh
I don't what he describes solves my issue. What I want is a standard Asp.Net web application have sub-application that is an MVC app. What he's doing is he has an MVC app reference a DLL to make use of another MVC dll. But this doesn't address the relationship I'm dealing with here... I don't think.
Moskie
mmmm I see, but the error message you shown: "The view 'Index' or its master could not be found. The following locations were searched: etc. " shows it's using MVC routing, but it's looking relative to the main app folder. So with VirtualPath folder maybe you could do the trick.
antonioh
By "VirtualPath" folder, do you mean a Virtual Directory, set up underneath the parent app, pointing to the Views folder of the sub-app? If so, it didn't change anything. I think that's because when dealing with sub-apps, '~' does refer to the home directory of the sub-application itself...
Moskie
A virtual path could be anything really, physical folder, db, virtual directory... It seems it's a bit different than the problem I had, so I'm afraid I cannot help much more. It surprises me it's not the same pattern though. Good luck, I hope somebody else can help ;)
antonioh
A: 

Make sure that you haven't made any spelling mistakes in the names of your Views directories. I was receiving the same error message and after 30 mins of head scratching realized that I had misspelled the folder name for one of my Views. The IDE did not pick this up in any meaningful way (i.e. it would have been nice if it explicitly told me that the path to the view that I was referencing was not correct -- "not found" could mean a few different things).

Rowan