Search code examples
azuresslasp.net-coreazure-web-app-servicevirtual-directory

Azure multiple sites in virtual directories


I have 3 asp.net core sites I need to deploy on the same domain (subdomains will not work with my SSL certificate).

virtual-directories-config

When I deploy the api and identity projects, they work fine. However, when deploying the single page app, api and identity stop working.

The page cannot be displayed because an internal server error has occurred.

The error appears instantly so it's probably failing early on from startup I guess. The single page app is working ok.

It seems the spa is interfering, I tried solutions from here to ignore the routes, but I get the same error.

I have tried the solution here to get a more descriptive error but to no avail.

Not sure where to go from here


Solution

  • The cause of the problem is that both the root application and the child app add the aspNetCore handler, causing the config system to blow up. You can see this by turning on Detailed error messages in the Azure Portal, and then finding the error page under D:\home\LogFiles\DetailedErrors. You'll see this error:

    Cannot add duplicate collection entry of type 'add' with unique key attribute 'name' set to 'aspNetCore'

    There are two approaches to solving this.

    The first is to use a location tag to prevent inheritance. Specifically, change your root app's web.config from something like this:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <system.webServer>
        <handlers>
          <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
        </handlers>
        <aspNetCore processPath="dotnet" arguments=".\myapp.dll" stdoutLogEnabled="false" stdoutLogFile="\\?\%home%\LogFiles\stdout" />
      </system.webServer>
    </configuration>
    

    to something like this:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <location path="." inheritInChildApplications="false">
        <system.webServer>
          <handlers>
            <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
          </handlers>
          <aspNetCore processPath="dotnet" arguments=".\myapp.dll" stdoutLogEnabled="false" stdoutLogFile="\\?\%home%\LogFiles\stdout" />
        </system.webServer>
      </location>
    </configuration>
    

    The second approach is to remove the <handlers> section from the sub-application to avoid the duplication (as suggested in the doc under Configuration of sub-applications):

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <system.webServer>
        <aspNetCore processPath="dotnet" arguments=".\mySubApp.dll" stdoutLogEnabled="false" stdoutLogFile="\\?\%home%\LogFiles\stdout" />
      </system.webServer>
    </configuration>