gpt4 book ai didi

asp.net-core - 从 Blazor 服务器下载文件时出现错误 : Circuit has been shut down due to error.

转载 作者:行者123 更新时间:2023-12-03 14:52:50 26 4
gpt4 key购买 nike

我使用 Blazor 服务器创建了一个 web 应用程序。 webapp的一部分是文件下载,如下:

// called on button click, initiates the download
private async Task OnDownloadRequest(FileEntry file)
{
NavManager.NavigateTo($"/download/{file.Id}", true);
}

// MVC controller
public class DownloadController
{
[HttpGet("~/download/{downloadId}")]
public async Task<IActionResult> Download([FromServices] MyContext dbContext, long downloadId, CancellationToken cancel)
{
File file = await dbContext.Files.FindAsync(downloadId);
Stream stream = new MemoryStream(file.Content);

var result = new FileStreamResult(stream, "application/octet-stream")
{
FileDownloadName = file.Name,
LastModified = file.LastModified
};

return result;
}
}

// Startup.cs Configure method contains:
app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub();
endpoints.MapControllerRoute("mvc", "{controller}/{action}");
endpoints.MapFallbackToPage("/_Host");
});
实际上文件的下载工作正常,但与此同时 Blazor 崩溃了:
blazor.server.js:19 [2020-09-05T11:33:02.200Z] Error: Circuit has been shut down due to error.
e.log @ blazor.server.js:19
blazor.server.js:1 [2020-09-05T11:33:02.202Z] Information: Connection disconnected.
任何人都知道为什么 blazor 在这种情况下崩溃以及如何修复它?

最佳答案

问题仅在 NET 5 Preview 8 中出现,在 NET Core 3.1 中不出现。提交于 https://github.com/dotnet/aspnetcore/issues/25646 的错误报告

关于asp.net-core - 从 Blazor 服务器下载文件时出现错误 : Circuit has been shut down due to error.,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63753510/

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