代码之家  ›  专栏  ›  技术社区  ›  XamDev

应用SSL证书后,内容配置为空,为什么?

  •  0
  • XamDev  · 技术社区  · 6 年前

    我们已经实现了一些下载功能。我们正在api端设置内容配置。通过这样做,我们的用户界面将从内容配置中获得文件名。

    在我们添加了SSL证书并将站点移动到特定于域的链接之前,这一切都很正常。

    现在内容配置又回来了 null 文件的下载方式是 无效的 作为名称,没有扩展名。

    下面是下载文件的代码。

    public IActionResult DownloadFile(int ID)
    {
        try
        {
            if (ValidateUsrToken())
            {
                using (ExcelPackage package = BAL.DownloadFile(ID))
                {
                    string fileName = Uri.EscapeDataString(package.File.Name);
    
                    System.Net.Mime.ContentDisposition cd = new System.Net.Mime.ContentDisposition
                    {
                        FileName = fileName,
                    };
    
                    Response.Headers.Add("Content-Disposition", cd.ToString());
    
                    return File(package.GetAsByteArray(), "application /vndopenxmlformats-officedocument.spreadsheetml.sheet");
                }
            }
            else throw new NullReferenceException();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    

    用户界面代码

    const disposition = res.headers.get('content-disposition') || '';
    if (disposition && disposition.indexOf('attachment') !== -1) {
       const filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
       const matches = filenameRegex.exec(disposition);
       if (matches != null && matches[1]) {
          filename = matches[1].replace(/['"]/g, '');
          filename = decodeURIComponent(filename);
       }
    } 
    

    我们的api&UI是在azure云上实现的。

    谢谢你的帮助。

    0 回复  |  直到 6 年前