Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# FilePathResult不适用于swf文件?_C#_Asp.net Mvc_Fileresult - Fatal编程技术网

C# FilePathResult不适用于swf文件?

C# FilePathResult不适用于swf文件?,c#,asp.net-mvc,fileresult,C#,Asp.net Mvc,Fileresult,我正在使用FileResult显示网站中的文件,如下所示: public ActionResult GetSwf(long id = 0) { if (id <= 0) return null; Attachment attachment = Service.GetAttachmentById(id); if (attachment == null) return null; string filename = attachment.Name; s

我正在使用FileResult显示网站中的文件,如下所示:

public ActionResult GetSwf(long id = 0)
{
    if (id <= 0) return null;
    Attachment attachment = Service.GetAttachmentById(id);
    if (attachment == null) return null;

    string filename = attachment.Name;
    string mimeType = "application/x-shockwave-flash";
    string absoluteFilePath = UploadedPaths.GetAbsolutePath(attachment.Path);

    return File(absoluteFilePath, mimeType, filename);
}
public ActionResult GetSwf(long id = 0)
{
    if (id <= 0) return null;
    Attachment attachment = Service.GetAttachmentById(id);
    if (attachment == null) return null;

    string filename = attachment.Name;
    string mimeType = "application/x-shockwave-flash";
    string absoluteFilePath = UploadedPaths.GetAbsolutePath(attachment.Path);

    byte[] bytes = System.IO.File.ReadAllBytes(absoluteFilePath);
    return new FileContentResult(bytes, mimeType);
}
以下标记不起作用,浏览器将下载文件而不是显示它

<object type="application/x-shockwave-flash" width="220" height="166" data="File/GetSwf/1232" class="flash-object" data-name="ads-file"></object>

出了什么问题,我该怎么解决呢?

最终,我找到了解决办法。 我不得不改变行动如下:

public ActionResult GetSwf(long id = 0)
{
    if (id <= 0) return null;
    Attachment attachment = Service.GetAttachmentById(id);
    if (attachment == null) return null;

    string filename = attachment.Name;
    string mimeType = "application/x-shockwave-flash";
    string absoluteFilePath = UploadedPaths.GetAbsolutePath(attachment.Path);

    return File(absoluteFilePath, mimeType, filename);
}
public ActionResult GetSwf(long id = 0)
{
    if (id <= 0) return null;
    Attachment attachment = Service.GetAttachmentById(id);
    if (attachment == null) return null;

    string filename = attachment.Name;
    string mimeType = "application/x-shockwave-flash";
    string absoluteFilePath = UploadedPaths.GetAbsolutePath(attachment.Path);

    byte[] bytes = System.IO.File.ReadAllBytes(absoluteFilePath);
    return new FileContentResult(bytes, mimeType);
}

你检查过浏览器插件吗?安装flash插件并重新检查我在chrome 38中有最新版本的flash Player。尝试将响应标头的内容处置属性模式设置为“内联”,看看这是否有区别。当返回FileResult时,此行为下载文件是正常的。。。您可以返回jsonnew{FilePath=};