Azure multiple sites in virtual directories

我只是一个虾纸丫 提交于 2019-12-12 23:20:15

问题


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

  • https://my-site.com (Single page app)
  • https://my-site.com/api (Web api)
  • https://my-site.com/identity (Identity server)

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


回答1:


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>


来源:https://stackoverflow.com/questions/47472306/azure-multiple-sites-in-virtual-directories

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!