[英]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.