【发布时间】:2023-03-14 04:54:01
【问题描述】:
目前,如果我想使用 asp.net core 和 angular,我会执行以下操作:
- 使用 Angular cli 创建客户端应用
- 创建一个 asp.net core mvc 应用程序
- 使用 Microsoft.AspNetCore.SpaServices.Extensions 将两者连接起来(spa 策略 = 代理)
- 修改mvc应用的
Index.html如下:
@section scripts {
<script src="runtime.js"></script>
<script src="polyfills.js"></script>
<script src="styles.js"></script>
<script src="vendor.js"></script>
<script src="main.js"></script>
}
<app-root></app-root>
- 像这样修改
_Layout.html:
<!DOCTYPE html>
<html lang="en">
<head>
<base href="/">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>App</title>
</head>
<body>
<h2 class="bg-dark text-white p-2">App</h2>
@RenderBody()
@RenderSection("Scripts", required: false)
</body>
</html>
然后我启动 Angular 服务器并运行 mvc 应用程序。如您所见,在这种情况下,我使用 mvc 应用程序的Index.html 并将角度内容投影到其中。我将只使用 asp.net 核心应用程序来服务 Rest api 请求,所以没有视图等。
我有三个问题:
- 上述是否是使用 angular 的便捷方式,其中 asp.net 核心部分仅充当 Rest api 服务器?如果不是,那是什么?
- 我也可以使用 Angular 客户端应用程序的
index.html吗?我的意思是,asp.net 核心部分实际上只服务于 api 请求,而应用程序的入口点将是 angular 客户端应用程序的index.html?
感谢您的回答/cmets。
【问题讨论】:
标签: angular asp.net-core asp.net-web-api