简体   繁体   English

ASP.NET中的内存映射文件

[英]Memory mapped files in ASP.NET

I am not sure if this is possible... Right now I create various .RDP files that my users download directly off the server, with code such as this: 我不确定是否可行...现在,我创建各种.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();

So a user would click a link and get a file link '~/Download/RemoteServer1234.RDP'. 因此,用户将单击链接并获得文件链接“〜/ Download / RemoteServer1234.RDP”。

I don't want these files on my server for various reasons (maintenance and security come to mind). 由于各种原因,我不希望这些文件在服务器上(想到维护和安全性)。 Is there a way to make 'fake files' and give a pointer to the client to just download data that resides in memory? 有没有一种方法可以制作“假文件”并提供一个指向客户端的指针,以仅下载驻留在内存中的数据? If so, then how does the server ultimately know when to remove any assigned memory? 如果是这样,那么服务器最终如何知道何时删除任何分配的内存?

Just use Response.Write() with a StringBuilder (via its ToString() method) containing the RDP file contents (which is an extremely simple format ). 只需将Response.Write()与包含RDP文件内容(这是一种非常简单的格式 )的StringBuilder(通过其ToString()方法)一起使用。 Of course you can pass an arbitrary string as the filename in the Content-disposition header. 当然,您可以在Content-disposition标头中传递任意字符串作为文件名。

Here's a description of the RDP format (which you apparently already write to a file): Remote Desktop File Format 这是RDP格式的描述(您显然已经将其写入文件了): 远程桌面文件格式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM