简体   繁体   中英

Header behaviour in a virtual MVC application in IIS

This is my current setup;

In IIS I have two hosted MVC applications, say App1 is hosted in app1.mydomain.com . It has a virtual MVC application (not directory) App2 hosted as app1.mydomain.com/app2 .

Both applications have a connection to the same WCF service. This WCF service requires headers in their requests and thus I have added behaviours for every call using this .

I have configured both applications' header behaviour correctly ( App1 has App1MessageHeaderInspector and App2 has App2MessageHeaderInspector ) and have configured both in their own Web.config.

So, App1 uses;

<client>
  <endpoint address="http://ws.mydomain.com/Service.svc" binding="basicHttpBinding"
    bindingConfiguration="BasicHttpBinding_IWebService" contract="WCFService.IWebService"
    name="BasicHttpBinding_IWebService" behaviorConfiguration="WebServiceEndpointBehaviour" />
</client>
<extensions>
  <behaviorExtensions>
    <add name="App1MessageHeaderInspector" type="App1.App1MessageHeaderBehaviourExtension, App1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null "/>
  </behaviorExtensions>
</extensions>
<behaviors>
  <endpointBehaviors>
    <behavior name="WebServiceEndpointBehaviour">
      <App1MessageHeaderInspector />
    </behavior>
  </endpointBehaviors>
</behaviors>

And App2 uses the same configuration, except that App1MessageheaderInspector is App2MessageHeaderInspector .

I have configured my routing in App1 to ignore everything going to /app2 ;

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    routes.IgnoreRoute("{*path}", new { path = @"app2\/(.*)" });
    //...
}

And I can succesfully view pages which do not require a connection to the WCF service (ie app1.mydomain.com/app2/Home/Index returns the correct view).

Now my problem is, as soon as I try to connect to the WCF service with App2 , I get the following error;

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: The type 'App1.App1MessageHeaderBehaviourExtension, App1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null ' registered for extension 'App1MessageHeaderInspector' could not be loaded.

But I don't want App2 to load the behaviours from App1 !

I have also tried to encapsulate <system.web> with <location inheritInChildApplications="false"> in App1 , but without success.

Both applications work as intended when testing from my local PC. There is no Windows authentication or anything like that involved.

I am quite stuck on this topic for a few days now. Any help is appreciated.

Configuration section are inherited/merged by default when a web application is configured under another one like in your case. As you've seen system.web section has its mechanism to break inheritance, but this just works for system.web and its children (possibly, not even all children).

Having said that, I would give a try at this (in your App2 config):

<extensions>
    <behaviorExtensions>
        <clear />
        <add name="App1MessageHeaderInspector" type="App1.App1MessageHeaderBehaviourExtension, App1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null "/>
    </behaviorExtensions>
</extensions>

Do you have the App1.dll in your bin directory under the virtual directory for app2? The message indicates that the dll cannot be found in the usual location (such as /bin)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM