简体   繁体   English

.NET Core 中 WebAPI 的 Angular UI,但主要目的仍然是 WebAPI,而不是前端应用程序

[英]Angular UI for a WebAPI in .NET Core while still the primary purpose is a WebAPI, not a frontend App

Any feedback much appreciated.非常感谢任何反馈。

I need to create a Web API (ASP.NET Core Web API), which does some basic CRUD operations.我需要创建一个 Web API(ASP.NET Core Web API),它执行一些基本的 CRUD 操作。 Thats no issue at all, and I need to create a simple Angular UI for the Web API as well.那完全没有问题,我还需要为 Web API 创建一个简单的 Angular UI。 Thats also no issue.那也没有问题。 But is there a way to combine both into a single application ?但是有没有办法将两者结合到一个应用程序中? WebAPI mainly and an optional UI part in Angular than having a second angular solution ? WebAPI 主要是 Angular 中的一个可选 UI 部分,而不是第二个角度解决方案? I know there is a visual studio project template where you create a .NET Core Angular Application, if I do that, how would I expose the API at the sametime to other clients as API, while still managing the Angular UI ?我知道有一个 Visual Studio 项目模板,您可以在其中创建 .NET Core Angular 应用程序,如果我这样做,我将如何将 API 作为 API 同时公开给其他客户端,同时仍然管理 Angular UI?

Put in another way, my .NET Core application should be primarily a WebAPI which should work independently and act like a WebAPI, while an optional part of it should have an Angular frontend connecting to the WebAPI.换句话说,我的 .NET Core 应用程序应该主要是一个 WebAPI,它应该独立工作并像 WebAPI 一样工作,而它的一个可选部分应该有一个连接到 WebAPI 的 Angular 前端。

You can view this as a matter of security for your WebAPI and how you expose connections to it.您可以将此视为 WebAPI 的安全问题以及如何公开与它的连接。 You can serve your API endpoints under one route, ie /api and you Angular application at you site route or host it elsewhere.您可以在一个路由下为您的 API 端点提供服务,即 /api 和您站点路由上的 Angular 应用程序或将其托管在其他地方。

If you follow the same practices for exposing the WebAPI cross origin, then your Angular application can consume the API in exactly the same way as any other client would.如果您遵循相同的实践来公开 WebAPI 跨源,那么您的 Angular 应用程序可以以与任何其他客户端完全相同的方式使用 API。

Followed @johnny's comment and it works !遵循@johnny 的评论,它有效!

All you have to do is compile your angular project and put it under wwwroot.您所要做的就是编译您的 angular 项目并将其放在 wwwroot 下。 Then you can navigate to your index.html page, set your webapi startup to serve static files and your done然后你可以导航到你的 index.html 页面,设置你的 webapi 启动以提供静态文件和你的完成

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 .NET Core 3.1 WebAPI 中托管 Angular 应用程序? - How to host an Angular app inside .NET Core 3.1 WebAPI? ASP.NET Core2 WebAPI和角度应用程序未在页面中呈现 - asp.net core2 webapi and angular app not rendering in the page ASP.NET Core WebAPI - .NET 7: Swagger UI 为空,但仍有 HTML 源 - ASP.NET Core WebAPI - .NET 7: Swagger UI is empty, but still have HTML source 如何使用 angular 修改 asp.net 核心 WebAPI 的 asp.net 身份 UI - How to modify asp.net Identity UI for asp.net core WebAPI with angular 如何从 Angular UI 向 WebAPI 核心方法传递值 - How to pass values to WebAPI core methods from Angular UI Asp.net 核心 webapi 获取从 Angular4 应用程序发布的空值 - Asp.net core webapi getting null value posted from Angular4 app .Net Core Docker WebApi RemoteCertificateChainError - 连接 2 Docker 容器(UI + API) - .Net Core Docker WebApi RemoteCertificateChainError - Connecting 2 Docker Containers (UI + API) 在带有 Entity Framework Core 的 ASP.NET Core WebAPI 的 PUT 方法中进行此检查的目的是什么? - What is the purpose of this check in this PUT method of ASP.NET Core WebAPI with Entity Framework Core? Angular 4前端和Windows Auth的.NET Core 2 WebAPI CORS问题 - .NET Core 2 WebAPI CORS problems with Angular 4 front end and Windows Auth 斑马打印机上的Angular + .Net Core WebApi打印标签 - Angular + .Net Core WebApi print labels on Zebra printer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM