0

I have a Blazor Server app which creates a zip file in memory and delivers that zip file via an call to a get method of an controller. I use following call inside of a button to start the download:

navigationManager.NavigateTo($"api/DownloadFile?RequestGuid={WebUtility.UrlEncode(RequestGuid.ToString())}", true);

Everything works fine, but 1 or 2 minutes after the successfull download the application crashs with following error:

Microsoft.AspNetCore.Components.Server.Circuits.RemoteNavigationManager[4] Navigation failed when changing the location to api/DownloadFile?RequestGuid=db296363-ec46-4661-a8f5-78f9537114bc System.Threading.Tasks.TaskCanceledException: A task was canceled. at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args) at Microsoft.JSInterop.JSRuntimeExtensions.InvokeVoidAsync(IJSRuntime jsRuntime, String identifier, Object[] args) at Microsoft.AspNetCore.Components.Server.Circuits.RemoteNavigationManager.<>c__DisplayClass13_0.<g__PerformNavigationAsync|0>d.MoveNext()

Is there any workaround on how to avoid this issue?

1 Answer 1

0

To avoid the issue, you could try use JS Interop to download the file instead of navigation.

@inject IJSRuntime JS

@code {
    private async Task TriggerDownload(Guid requestGuid)
    {
        var url = $"api/DownloadFile?RequestGuid={WebUtility.UrlEncode(requestGuid.ToString())}";
        await JS.InvokeVoidAsync("window.open", url, "_blank");
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.