gpt4 book ai didi

asp.net-core - 如何从 ASP.NET Core 中的 Controller 操作提供 blazor 应用程序

转载 作者:行者123 更新时间:2023-12-04 09:37:15 27 4
gpt4 key购买 nike

我之前曾在 3.0 预览版发布时向 Blazor 提出过这个问题。
Is there a way to serve a Blazor app from a specific controller action in a MVC app?
从那时起 Blazor 3.2 已经到来,我对如何实现这一点进行了一些研究,我尝试按照这个 github 问题上的示例进行操作,但并没有真正让它工作。
https://github.com/dotnet/aspnetcore/issues/20642
想法?

最佳答案

尝试这个:

public IActionResult MyAction([FromServices] IWebHostEnvironment webHost)
{
var file = webHost.WebRootFileProvider.GetFileInfo("index.html");
return PhysicalFile(file.PhysicalPath, "text/html");
}
并将 Startup.cs 中的回退更改为:
app.UseEndpoints(endpoints =>
{
...
endpoints.MapFallbackToController("MyAction","controller")
});

关于asp.net-core - 如何从 ASP.NET Core 中的 Controller 操作提供 blazor 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62514446/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com