Open a file in another window without blocking subsequent calls/concurrent calls from the view

Asked By: Anonymous

In one of our page we do have a file view option. While clicking on the file we are calling a controller action method which returns a FileResult. This file is showing in a different tab. The issue is because of the file size, its taking some seconds to load the file, until the file is returned from server the other operations cannot be done from the UI. The subsequent requests are hitting only when this operation is completed. Is there any way to open this file without affecting the subsequent requests?

The current approach we are using here is below.

public async Task<FileResult> OpenAttachment(string attachid)
    var attachment = await Task.Run(() => this._commService.OpenAttachment(attachid));
    if (attachment == null)
        throw new PnnCustomExceptions("File not found");

    attachment.FileName = attachment.FileName.AddAttachmentNameExtension(attachment.MimeType);

    var cd = new ContentDisposition
        Inline = true,
        FileName = attachment.FileName

    Response.AddHeader(CoreConstants.ContentDisposition, cd.ToString());
    Response.AddHeader(CoreConstants.WindowTarget, CoreConstants.WindowTargetBlank);
    Response.BufferOutput = false;
    return File(attachment.Data, attachment.MimeType);

Is there any way we can do this in MVC?


Answered By: Anonymous

The issue is related to concurrent requests in the same session. We have added a session state behavior in our controller to fix this issue. Since this controller never going to update the session we have added a decorator like below in the controller

  public class AttachmentController

Since this controller is decorated with session readonly, it wont queue the concurrent requests.

techinplanet staff

techinplanet staff

Windows 10 Kaufen Windows 10 Pro Office 2019 Kaufen Office 365 Lizenz Windows 10 Home Lizenz Office 2019 Home Business Kaufen windows office 365 satın al follower kaufen instagram follower kaufen porno