Asp.net mvc 5 Mvc 5返回文件mimetype不工作

Asp.net mvc 5 Mvc 5返回文件mimetype不工作,asp.net-mvc-5,mime-types,Asp.net Mvc 5,Mime Types,我想要实现的是从指定文件夹返回具有正确文件类型和指定名称的文件。“我的操作”返回文件,但未设置内容类型。我希望从我的文档路径将其动态指定为。在调试模式下,我可以看到文件的扩展名设置为contentType参数 public async Task<FileResult> Download(int? id, string refId, int? categoryId = null) { var document = await _documentService.

我想要实现的是从指定文件夹返回具有正确文件类型和指定名称的文件。“我的操作”返回文件,但未设置内容类型。我希望从我的文档路径将其动态指定为。在调试模式下,我可以看到文件的扩展名设置为contentType参数

public async Task<FileResult> Download(int? id, string refId, int? categoryId = null)
    {

        var document = await _documentService.GetDocument( Id = id.Value );
        if (document == null || document.RefId.ToString() != refId)
        {
            throw new Exception("NotFound");
        }

      var directory = await _categoryService.GetCategory(Session.UserId.Value, categoryId);
        var archive = Server.MapPath(directory + "/" + document.FileName);

        var contentType = MimeMapping.GetMimeMapping(document.FileName);



        return File(archive, contentType, document.PureFileName);
    }
公共异步任务下载(int?id,string refId,int?categoryId=null)
{
var document=wait\u documentService.GetDocument(Id=Id.Value);
if(document==null | | document.RefId.ToString()!=RefId)
{
抛出新异常(“NotFound”);
}
var directory=await_categoryService.GetCategory(Session.UserId.Value,categoryId);
var archive=Server.MapPath(目录+“/”+文档.FileName);
var contentType=MimeMapping.GetMimeMapping(document.FileName);
返回文件(归档、contentType、document.PureFileName);
}

提前感谢。

我在document.PureFileName参数的末尾添加了文件扩展名,现在它可以正常工作了