1

I've got an azure website (MVC) configured and everything was working fine until i tried adding a WebAPI project to solution which is deployed to azure.

My virtual directory mapping looks like

  1. virtual ----- physical --- IsApplication
  2. / ----- site\wwwroot\ ------ IsApplicaiton (yes) [Path for mvc project] Application
  3. /api ---- site\services\ ------- IsApplication (no)
  4. /api/code ------ site\services\code\ ------- IsApplication (yes) [Path for WebAPI project]

The MVC application is working fine but the WebAPI application (which is blank scaffold from VS WebApplication -> WebAPI2) is not. After modifying WebApi's web.config to disable custom errors page I found out that the problem is the namespace included in MVC application's web.config (of course WebAPI project does not possess reference to it and it shouldn't). But why does WebAPI even bother itself with web.config sitting in MVC application when it has its own?

Gus
  • 3,534
  • 1
  • 30
  • 39
user2184057
  • 924
  • 10
  • 27
  • 1
    If you were running web api in the same site/apppool as MVC then there is an order of precedence needed in the App_Start() method. But it sounds like you're not doing that. Can you include the exception detail? – Stinky Towel Oct 07 '16 at 16:40
  • I don't know about apppools in Azure and how it works. But what i want to do is to host few application under one site. MVC is supposed to be a client for a WebAPI application. As far as i understand web.config inheritance it should inherit settings from parent folders not parent virtual directories. – user2184057 Oct 07 '16 at 16:44

1 Answers1

1

Web.config settings "waterfall" down within applications. So if you have an application hosted at the root '/' and then another application hosted under that (i.e. '/api/code') then all of the settings from the root web application's web.config will be added into the settings of the sub application's web.config. The physical location of the application is irrelevant to this behavior. All of this is driven by the virtual directory structure. This is why you are seeing errors related to your MVC app's namespace in your WebAPI app.

To fix this you should use <remove name="..." /> or <clear /> tags or inheritInChildApplications attribute in your WebAPI's web.config to remove settings that are passed down from your MVC application. An example of how to do that can be found in this SO answer: https://stackoverflow.com/a/5968658/6387007

For more information on web.config inheritance you can check out this MSDN article too: https://msdn.microsoft.com/en-us/library/ms178685.aspx

Community
  • 1
  • 1
sam2929
  • 479
  • 7
  • 14