Reputation: 964
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
- virtual ----- physical --- IsApplication
- / ----- site\wwwroot\ ------ IsApplicaiton (yes) [Path for mvc project] Application
- /api ---- site\services\ ------- IsApplication (no)
- /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?
Upvotes: 1
Views: 771
Reputation: 479
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
Upvotes: 1