文件结果 + 重定向到错误时的操作

本文关键字:操作 错误 结果 重定向 文件 | 更新日期: 2023-09-27 18:34:35

当我调用网络服务以获取凭证并且网络服务是 KO 时,我有时会出错。我需要重定向到另一个操作:我需要做这样的事情:

  public virtual FileResult Ticket(int operationCategoryId, int orderId)
    {
        try
        {
            var orderDetail = _orderDetailBusiness.GetOrderDetail(operationCategoryId, orderId);
            byte[] ticketContent = _vpTicketMinuteBusiness.GetTicketContent(orderDetail.Parcels);
            return File(ticketContent, "application/pdf", orderId + ".pdf");
        }
        catch (NullReferenceException exception)
        {
            return RedirectToAction("Error");
        }
    }

我该怎么做?

文件结果 + 重定向到错误时的操作

试试这个:

 return new FileStreamResult(ms, "application/ms-excel")
            {
                FileDownloadName = "yourfile.xlsx",
            };