首页 > 解决方案 > 申请SSL证书后内容配置为空,为什么?

问题描述

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

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

现在内容配置又回来null了,文件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 云上实现的。

对此的任何帮助表示赞赏。

标签: c#angularjsazuressl-certificateasp.net-core-webapi

解决方案


推荐阅读