如何部署ASP.NET Core 6+本地的角度水疗
问题:
我使用了Visual Studio的角模板创建了一个Angular Freontend应用程序和ASP.NET Core后端应用程序。
我的目标是:
我想分享我的后端ASP.NET Core 6应用程序和Angular 13前端应用程序,以便有人可以在另一台计算机上测试该应用,而无需构建或安装依赖项。
有什么方法可以使ASP.NET核心应用程序提供index.html文件?这足够了吗? 我将如何实现?
到目前为止,我已经尝试了以下操作:
app.UseStaticFiles(new StaticFileOptions {
FileProvider = new PhysicalFileProvider(builder.Environment.ContentRootPath),
RequestPath = "/index.html"
});
app.UseRouting();
app.MapFallbackToFile("index.html"); ;
app.MapHub<MainHub>("/main");
我运行以下命令来构建应用程序:
dotnet build -r win-x64 -c Release
我打开了结果.exe .exe
文件,并向LocalHost打开了浏览器:5000 URI。
但是,我得到的只是404找不到
状态代码。
The problem:
I have created an angular freontend app and an asp.net core backend app using the angular template for visual studio.
My goal:
I want to share my backend asp.net core 6 application and my Angular 13 frontend application, so that someone can test the app on another computer, without having to build or install dependencies.
Is there any way to make the asp.net core application serve the index.html file? Would this suffice?
How would I achieve this?
So far I have tried this:
app.UseStaticFiles(new StaticFileOptions {
FileProvider = new PhysicalFileProvider(builder.Environment.ContentRootPath),
RequestPath = "/index.html"
});
app.UseRouting();
app.MapFallbackToFile("index.html"); ;
app.MapHub<MainHub>("/main");
I then ran the following command to build the app:
dotnet build -r win-x64 -c Release
I opened the resulting .exe
file and opened a browser to the localhost:5000 uri.
However all I get is a 404 Not Found
status code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经弄清楚了。
我错误地运行了命令来构建,而不是发布该应用程序的命令。
以下命令:
做到了。它在
版本
构建目录文件夹中创建了一个发布
文件夹。在Standrd WebContent Path内部wwwroot
是所有必要的Angular文件,Web应用程序需要服务。然后,我将代码更改为:
这似乎不是必需的,因为这些是标准配置。
I have figured it out.
I erroneously was running the command to build and not the command to publish the application.
The following command:
did the trick. It created a
publish
folder within theRelease
build directory folder. There, inside the standrd webcontent pathwwwroot
, were all the necessary angular files, the web app needs to serve.Then I changed my code to:
this seems to not be necessary, however, since these are the standard configurations.