【发布时间】:2018-11-01 12:23:35
【问题描述】:
我不知道如何在新的 Chrome 标签页中打开 pdf。以下代码适用于 Internet Explorer,但不适用于 Chrome。我检查了 Chrome 中的设置,设置如下:
我的看法:
@Html.ActionLink("View", "OpenFileEncrypted", "Storage", new { fileNumber = item.accession_number, fileType = 2, openType = "NewTab" }, new { @class = "btn btn-primary ViewDownloadButton", @runat="server", @target = "_blank", @onclick = "javascript:clickView(" + item.accession_number + ")" })
javascript 函数 ClickView 检查网络上的复选框 页面。
我的控制器:
public ActionResult OpenFileEncrypted(int? fileNumber, int? fileType, string openType)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = GetContainer(blobClient, Convert.ToInt32(fileType));
KeyVaultKeyResolver cloudResolver = new KeyVaultKeyResolver(GetToken);
var fileName = Convert.ToString(fileNumber) + ".pdf";
CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName);
BlobEncryptionPolicy policy = new BlobEncryptionPolicy(null, cloudResolver);
BlobRequestOptions options = new BlobRequestOptions() { EncryptionPolicy = policy };
var memStream = new MemoryStream();
blockBlob.DownloadToStream(memStream, null, options, null);
if (openType == null)
{
openType = "NewTab";
}
order_info OInfo = Ldb.order_info.Where(o => o.accession_number == fileNumber).FirstOrDefault();
switch (openType)
{
case "NewTab":
Response.AddHeader("Content-Disposition", "Inline; filename=" + fileName);
OInfo.ReportViewed = true;
break;
case "Download":
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
OInfo.ReportDownloaded = true;
break;
}
if (OInfo != null)
{
Ldb.Entry(OInfo).State = EntityState.Modified;
Ldb.SaveChanges();
}
return File(memStream.ToArray(), blockBlob.Properties.ContentType);
它适用于 IE,但不适用于 Chrome。单击该按钮时,它会打开一个新选项卡,然后打开一个下载框以命名并选择下载 .pdf 的文件夹。
我做错了什么?
【问题讨论】:
-
必须是扩展pdf
标签: c# asp.net-mvc google-chrome pdf tabs