【问题标题】:Memory mapped files in ASP.NETASP.NET 中的内存映射文件
【发布时间】:2010-07-23 05:40:50
【问题描述】:

我不确定这是否可行...现在我创建了各种 .RDP 文件,我的用户可以直接从服务器下载这些文件,代码如下:

        System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);
        Response.Clear();
        Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);
        Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
        Response.ContentType = "Content-Type=application/x-rdp rdp;charset=ISO-8859-1";
        Response.AddHeader("Content-Length", fileInfo.Length.ToString());
        Response.WriteFile(fileInfo.FullName);
        Response.End();

所以用户会点击一个链接并获得一个文件链接“~/Download/RemoteServer1234.RDP”。

出于各种原因(考虑到维护和安全性),我不希望这些文件出现在我的服务器上。有没有办法制作“假文件”并给客户端一个指针来下载驻留在内存中的数据?如果是这样,那么服务器最终如何知道何时删除任何分配的内存?

【问题讨论】:

    标签: c# asp.net memory file-io


    【解决方案1】:

    只需将 Response.Write() 与包含 RDP 文件内容的 StringBuilder(通过其 ToString() 方法)一起使用(这是一个非常简单的 format)。当然,您可以在 Content-disposition 标头中传递任意字符串作为文件名。

    以下是 RDP 格式的描述(您显然已经将其写入文件): Remote Desktop File Format

    【讨论】:

      猜你喜欢
      • 2016-02-23
      • 1970-01-01
      • 2010-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-01
      相关资源
      最近更新 更多