C#/网:返回一个文件浏览器? [英] C#/.Net: Returning a file to the browser?

查看:157
本文介绍了C#/网:返回一个文件浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着<一href="http://stackoverflow.com/questions/2229963/jquery-media-plugin-playing-file-outside-the-webroot">this问题它是建议我应该创建一个服务器端的文件,该文件可以从文件系统恢复文件。我会如何在C#和.NET这样做。我想我通过文件名作为查询字符串,这是由网页读取和文件恢复。真的不知道从哪里开始对这个从作弄点。

Following this question it was recommend that I should create a server side file that can return a file from the file system. How would I go about doing this in c# and .net. I imagine I pass the filename as a query string, this is read by the page and the file returned. Not really sure where to start on this from a codding point.

推荐答案

您可以使用Response.WriteFile方法来发送文件的内容,虽然这可能会失败,更大的文件。

You can use the Response.WriteFile method to send the contents of the file, though this may fail with larger files.

要小心,不要让任何文件名在查询字符串中指定,因为用户可以再使用该访问服务器上的任意文件。最好是有被允许与各1名的文件的数据库,并期待在查询字符串提供对这个数据库来获取文件名的名称。

Be careful not to allow any filename to be specified in your query string, as users could then use this to access any file on your server. Better to have a database of files that are allowed with a name for each one, and look up a name supplied in the query string against this database to get the filename.

这篇关于C#/网:返回一个文件浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆