Iis 从UNC路径读取文件并在HTTP请求中设置正确的MIME类型

Iis 从UNC路径读取文件并在HTTP请求中设置正确的MIME类型,iis,iis-7,streaming,mime,filestream,Iis,Iis 7,Streaming,Mime,Filestream,我如何从UNC路径读取文件,发现正确的MIME类型,并将其流式输出到浏览器 我觉得我是在重新发明IIS,而且我还必须为每个文件扩展名维护自己的MIME类型数据库。上述要求听起来合理吗,还是有更好的方法 我计划通过IIS7上的浏览器HTTP Get请求将其流式输出。如果重要的话,我也在同一台服务器上运行Cognos。任何框架都可以(WCF、ASPX等)使用WCF它非常基本: 此代码可以托管在IIS/Service/WAS/etc下。 我从来没有找到一个方便的方法来处理mime类型,您需要有自己的d

我如何从UNC路径读取文件,发现正确的MIME类型,并将其流式输出到浏览器

我觉得我是在重新发明IIS,而且我还必须为每个文件扩展名维护自己的MIME类型数据库。上述要求听起来合理吗,还是有更好的方法


我计划通过IIS7上的浏览器HTTP Get请求将其流式输出。如果重要的话,我也在同一台服务器上运行Cognos。任何框架都可以(WCF、ASPX等)

使用WCF它非常基本: 此代码可以托管在IIS/Service/WAS/etc下。
我从来没有找到一个方便的方法来处理mime类型,您需要有自己的db,它将文件扩展名映射到mime类型

[ServiceContract(SessionMode = SessionMode.NotAllowed)]
public interface IMediaRetriver
{
  [OperationContract]
  [WebGet(UriTemplate = "/get?f={fileName}")]
  Stream Get(string fileName);
}


[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class MediaRetriver : IMediaRetriver
{
    public Stream Get(string fileName)
    {
        // pro tips
        // this will cause the file dialog to show the file name instead of "get"
        WebOperationContext.Current.OutgoingResponse.Headers.Add(
          "Content-disposition", string.Format("inline; filename={0}", fileName));           
        WebOperationContext.Current.OutgoingResponse.ContentType = 
           "application/octet-stream";

        // you want to add sharing here also
        return File.Open(fileName)
    }
}

使用WCF是非常基本的: 此代码可以托管在IIS/Service/WAS/etc下。
我从来没有找到一个方便的方法来处理mime类型,您需要有自己的db,它将文件扩展名映射到mime类型

[ServiceContract(SessionMode = SessionMode.NotAllowed)]
public interface IMediaRetriver
{
  [OperationContract]
  [WebGet(UriTemplate = "/get?f={fileName}")]
  Stream Get(string fileName);
}


[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class MediaRetriver : IMediaRetriver
{
    public Stream Get(string fileName)
    {
        // pro tips
        // this will cause the file dialog to show the file name instead of "get"
        WebOperationContext.Current.OutgoingResponse.Headers.Add(
          "Content-disposition", string.Format("inline; filename={0}", fileName));           
        WebOperationContext.Current.OutgoingResponse.ContentType = 
           "application/octet-stream";

        // you want to add sharing here also
        return File.Open(fileName)
    }
}

@谢伊,刚刚更新了question@Shay,刚更新了question@Maker我不知道有没有这样的官方API这里有一个API可以让一切都完整:@Maker我不知道有没有这样的官方API这里有一个API可以让一切都完整: