Asp.net可重复使用的控件,在直接单击文件时下载文件扩展名为.ashx

时间:2017-04-05 07:05:47

标签: asp.net wcf web-controls

我有一个asp.net可重用控件,当直接点击文件下载文件扩展名.ashx时,只在IE上发生,并且它在firefox上工作正常。 This is what i' am getting 这就是我如何调用Control:

<a data-fancybox-type="iframe" class="fancybox" data-fancybox-group="gallery" title="fileName" href="AttachmentControl/DownloadAttachment.ashx?SourceId=6&id=1&attachmentSource=download"><i class="fa fa-file-image-o"></i> <span>fileName</span></a>

此控件正在调用WCF服务:

AttachmentSvc.IAttachmentService clientDownload = new AttachmentSvc.AttachmentServiceClient();
AttachmentSvc.DownloadRequest requestData = new AttachmentSvc.DownloadRequest();

AttachmentSvc.RemoteFileInfo fileInfo = new AttachmentSvc.RemoteFileInfo();
requestData.FileName = fileName;
if (!String.IsNullOrEmpty(requestData.FileName))
{
  fileInfo = clientDownload.DownloadFile(requestData);
  byte[] arrayFile = ReadFully(fileInfo.FileByteStream);
  file = Convert.ToBase64String(arrayFile);
}

wcf服务本身的代码如下:

RemoteFileInfo result = new RemoteFileInfo();
var templateDestinationFolderPath = PSSConfigHelper.AttachmentsUrlPrimaryNode();
string filePath = Path.Combine(@templateDestinationFolderPath, request.FileName);
System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);

// check if exists
if (!fileInfo.Exists) throw new System.IO.FileNotFoundException("File not found", request.FileName);

// open stream
System.IO.FileStream stream = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);

// return result
result.FileName = request.FileName;
result.Length = fileInfo.Length;
result.FileByteStream = stream;

0 个答案:

没有答案