首页 > 解决方案 > 在本地 iis 上提供 .net core 和 angular 5 应用程序

问题描述

我有以下设置:

我想将它们都托管在一个 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"];
        }
    });

任何人都知道我在哪里可以找到有关此的一些说明?

标签: angulariisasp.net-coreasp.net-core-webapi

解决方案


设法让它工作,

万一有人出现,这对我有用:

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>

希望它可以帮助某人


推荐阅读