angular - 在本地 iis 上提供 .net core 和 angular 5 应用程序
问题描述
我有以下设置:
- 一个 .net 核心 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"];
}
});
任何人都知道我在哪里可以找到有关此的一些说明?
解决方案
设法让它工作,
万一有人出现,这对我有用:
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>
希望它可以帮助某人
推荐阅读
- reactjs - Redux Saga + Socket 延迟
- python - 为什么用 Numba 进行矩阵乘法很慢?
- docker - 无法在 Windows 中将文件夹挂载到 docker 容器中
- java - 尝试在 Java 中添加到 ArrayList 时出现空指针异常
- spring - 使用 keycloak 创建用户
- java - 注释快捷方式(Hibernate 的@Id、@GeneratedValue、@SequenceGenerator)
- spring - 在 spring 中创建实体时如何触发 setter
- d3.js - D3 版本 6 - 计算条形图的条形宽度
- asp.net - asp .net 中的 Ajax 调用在 Chrome 中运行良好,在 Edge 中,而不是在 Firefox 中
- javascript - 如何获取状态以初始化使用原始组件中的数据呈现的新组件的状态?