如何部署ASP.NET Core 6+本地的角度水疗

发布于 2025-01-31 16:00:22 字数 794 浏览 2 评论 0原文

问题:

我使用了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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

亢潮 2025-02-07 16:00:22

我已经弄清楚了。

我错误地运行了命令来构建,而不是发布该应用程序的命令。

以下命令:

dotnet publish -r win-x64 -c Release

做到了。它在版本构建目录文件夹中创建了一个发布文件夹。在Standrd WebContent Path内部wwwroot是所有必要的Angular文件,Web应用程序需要服务。

然后,我将代码更改为:

app.UseStaticFiles();
app.UseRouting();

app.MapFallbackToFile("index.html", new StaticFileOptions() {
    ServeUnknownFileTypes = true,
    FileProvider = new PhysicalFileProvider(builder.Environment.WebRootPath)
});

app.MapHub<MainHub>("/main");

这似乎不是必需的,因为这些是标准配置。

I have figured it out.

I erroneously was running the command to build and not the command to publish the application.

The following command:

dotnet publish -r win-x64 -c Release

did the trick. It created a publish folder within the Release build directory folder. There, inside the standrd webcontent path wwwroot, were all the necessary angular files, the web app needs to serve.

Then I changed my code to:

app.UseStaticFiles();
app.UseRouting();

app.MapFallbackToFile("index.html", new StaticFileOptions() {
    ServeUnknownFileTypes = true,
    FileProvider = new PhysicalFileProvider(builder.Environment.WebRootPath)
});

app.MapHub<MainHub>("/main");

this seems to not be necessary, however, since these are the standard configurations.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文