在 IIS 默认网站下托管 .Net Core 应用程序和 Angular 应用程序

320*_*ser 6 iis web-hosting asp.net-core aspnetboilerplate angular

我正在使用带有角度的 ASP.net 核心样板。我尝试在 IIS localhost 下分别托管两个应用程序的 Angular 网站和 .NET 核心网站,没有问题。

但是当我想在公共上部署我的应用程序时,我遇到了这个问题:
1- 我只有一个公共 IP 重定向到 IIS 默认网站,并且每个应用程序都有一个不同的端口。
**因此,前端和后端都应托管在具有不同端口的 IIS 默认网站下。

这适用于 .NET 核心和 Angular 吗?**

更新

这是我的 appsetting.json

{

  "ConnectionStrings": {
    "Default": "Server=localhost\\SQLEXPRESS; Database=MyDb;User Id=admin;Password=1234"
  },
  "App": {
    "ServerRootAddress": "http://localhost:21021/",
    "ClientRootAddress": "http://localhost:4200/",
    "CorsOrigins": "http://localhost:4200,http://localhost:8080,http://localhost:8081,http://localhost:3000"
  },
  "Authentication": {
    "JwtBearer": {
      "IsEnabled": "true",
      "SecurityKey": "MyApp_C421AAEE0D114E9C",
      "Issuer": "MyApp",
      "Audience": "MyApp"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

更新 2

角度 web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <staticContent>
      <remove fileExtension=".json" />
      <mimeMap fileExtension=".json" mimeType="application/json" />
      <mimeMap fileExtension="woff" mimeType="application/font-woff" />
      <mimeMap fileExtension="woff2" mimeType="application/font-woff" />
    </staticContent>
    <!-- IIS URL Rewrite for Angular routes -->
    <rewrite>
      <rules>
        <rule name="Angular Routes" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
          </conditions>
          <action type="Rewrite" url="/" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)

角度 appconfig.production.json

{
  "remoteServiceBaseUrl": "http://localhost:21021",
  "appBaseUrl": "http://localhost:4200",
  "localeMappings": [
    {
      "from": "pt-BR",
      "to": "pt"
    },
    {
      "from": "zh-CN",
      "to": "zh"
    },
    {
      "from": "he-IL",
      "to": "he"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

Gou*_*arg 4

以下是一些步骤:

\n\n

先决条件

\n\n

客户端别名=>需要在iis中添加应用程序的客户端应用程序的路径名

\n\n

Service Alias => 需要在iis中添加应用程序的服务应用程序的路径名

\n\n
    \n
  1. 下载适用于 Windows 的 .NET Core 3.0 运行时和托管捆绑包,或者您可以根据您的项目找到确切的版本\n https://dotnet.microsoft.com/download/dotnet-core/thank-you/runtime-aspnetcore-3.0.0 -windows-hosting-bundle-安装程序
  2. \n
  3. 要在临床内容编辑器中设置 Angular 8 基础设施,需要安装 IIS 扩展“URL Rewrite\xe2\x80\x9d” https://www.iis.net/downloads/microsoft/url-rewrite
  4. \n
\n\n

前端:

\n\n
    \n
  1. 构建你的角度运行ng build --prod --base-href=/client-alias/

  2. \n
  3. 转到 IIS 中的默认网站

  4. \n
  5. 添加应用程序

  6. \n
  7. 添加别名并将物理路径指向您的分区在角度应用程序中

  8. \n
  9. 你可以测试这个http://localhost/client-alias

    \n\n

    后端(https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.1#create-the-iis-site

  10. \n
  11. 发布API项目,以便我们可以将内容复制到API服务的新Web应用程序中。

  12. \n
  13. 创建应用程序池,其 .net CLR 版本为“无托管代码”

  14. \n
  15. 在 IIS 中,为 API 服务创建一个新的 Web 应用程序,并在步骤 9 中添加应用程序池,并在步骤 8 中添加已发布文件夹的物理路径。

  16. \n
\n\n

现在这两个应用程序运行在http://127.0.0.1/client-aliashttp://127.0.0.1/service-alias上

\n\n

您可以将您的 IP(8080) 公开,而无需打开其他端口。

\n