代码之家  ›  专栏  ›  技术社区  ›  Jester

在本地iis上提供.net core和angular 5应用程序

  •  0
  • Jester  · 技术社区  · 6 年前

    我有以下设置:

    • 一个单独项目中的角度应用程序

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

    我试图从虚拟文件夹运行.net核心web api项目,但没有成功。执行404次

    配置服务

        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"];
            }
        });
    

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

    1 回复  |  直到 6 年前
        1
  •  1
  •   Jester    6 年前

    设法让它工作,

    万一有人来了这对我来说很有用:

    1.)使站点应用程序池与.net core协同工作:

    enter image description here

    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核心web api应用程序部署到此文件夹中。

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

    <?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
  •  0
  •   Fletch    5 年前

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