【问题标题】:serve .net core and angular 5 app on local iis在本地 iis 上提供 .net core 和 angular 5 应用程序
【发布时间】:2019-02-21 13:00:45
【问题描述】:

我有以下设置:

  • .net core web api 2.1.x 应用程序
  • 单独项目中的 Angular 应用程序

我想将它们都托管在一个 iis 站点中,以便它们像这样:

localhost\Site\ < --- angular app
localhost\Site\Api\ < --- web api app

我尝试从虚拟文件夹运行 .net core web api 项目,但没有成功。获取 404 执行

如果我直接托管 Web api 项目(将应用程序路径绑定到 \Api 文件夹),则 Web api 可以工作。但是那个应用程序还需要提供静态文件女巫它由于某种原因即使我启用了也不想做:

配置服务

    services.AddSpaStaticFiles(configuration =>
    {
        configuration.RootPath = "App";
    });

...

配置

    app.UseStaticFiles(new StaticFileOptions()
    {
        OnPrepareResponse = (context) =>
        {
            // Disable caching for all static files.
            context.Context.Response.Headers["Cache-Control"] = Configuration["StaticFiles:Headers:Cache-Control"];
            context.Context.Response.Headers["Pragma"] = Configuration["StaticFiles:Headers:Pragma"];
            context.Context.Response.Headers["Expires"] = Configuration["StaticFiles:Headers:Expires"];
        }
    });

有人知道我在哪里可以找到有关此的说明吗?

【问题讨论】:

    标签: angular iis asp.net-core asp.net-core-webapi


    【解决方案1】:

    设法让它工作,

    如果有人遇到这个,这对我有用:

    1.) 使站点应用程序池与 .net 核心一起使用:

    2.) 在名为 app 的站点下创建一个应用程序 将 Angular 应用程序部署到该文件夹​​(不要忘记使用 base-href 构建 Angular 应用程序以说明该文件夹) 将 web.config 更改为(查看 headers.remove ):

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <location path="." inheritInChildApplications="false">
        <system.webServer>
          <handlers>
            <remove name="aspNetCore" />
          </handlers>
        </system.webServer>
      </location>
    </configuration>
    

    3.) 在名为 backend 的站点下创建另一个应用程序,例如:

    将 .net core web api 应用程序部署到此文件夹中。

    web.config 更改为(删除注释掉的标头部分很重要):

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <system.webServer>
           <!-- <handlers> -->
             <!-- <remove name="aspnetcore" path="*" verb="*" modules="aspnetcoremodule" resourcetype="unspecified" />  -->
           <!-- </handlers>  -->
          <aspNetCore processPath="dotnet" arguments=".\core.rest.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
        </system.webServer>
    </configuration>
    

    希望对某人有所帮助

    【讨论】:

      【解决方案2】:

      我也有类似的问题,发现 .NET Core 应用程序和 Angular 应用程序必须在 IIS 中配置为同一网站下的单独应用程序。这可能是一个众所周知的事实,但我在任何地方都找不到它说明

      【讨论】:

        猜你喜欢
        • 2019-04-02
        • 2020-09-10
        • 2020-02-26
        • 2020-06-12
        • 1970-01-01
        • 2020-09-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多