在IIS6中,如何提供对远程服务器上静态文件的经过身份验证的访问
我们有一个 ZIP 文件库,希望可以在 ASP.NET 站点上下载。
这些文件位于可从网络场访问的 NAS 设备上。
以下是我们的初始策略:
- 将 IIS 虚拟目录映射到路径 /zipfiles 处的共享驱动器
- 用户可以在给定 URL 时下载 zip 文件
。但是,如果用户共享文件的链接,则任何人都可以下载它们。相反,我们希望在我们的站点中使用 ASP.NET 表单身份验证来验证用户的请求,然后再启动文件传输。
几个问题: 对 zip 文件的请求由 IIS 处理,而不是 ASP.NET。因此它不受表单身份验证的约束。 此外,我们不希望 ASP.NET 处理该请求,因为它会占用 ASP.NET 线程并且无法扩展以下载大文件。因此,配置 asp.net dll 来处理 *.zip 请求不是一个选项。
对此有什么想法吗?
我们反复提出的一个想法是: 初始下载请求将针对 ashx 处理程序。该处理程序将在身份验证后生成一个下载令牌,并将其保存到数据库中。然后,用户将被重定向到在 QueryString 中附加了令牌的文件(例如 /files/xyz.zip?token=123456789)。 ISAPI 插件将用于检查令牌。此外,令牌将在 x 时间后过期。 对此有什么想法吗?我还没有实现 ISAPI 插件,所以我不确定这是否有效。
我想避免自定义编码,因为安全是一个问题,并且我更喜欢使用经过时间考验的解决方案。
We have a library of ZIP files that we would like to make available for download at an ASP.NET site.
The files are sitting on a NAS device that is accessible from out web farm.
Here is our initial strategy:
- Map an IIS virtual directory to the shared drive at path /zipfiles
- Users can download the zip files when given the URL
However, if users share links to the files, anyone can download them. We would instead like to make use of the ASP.NET forms authentication in our site to validate users' requests before initiating the file transfer.
A few problems:
A request for a zip file is handled by IIS, not ASP.NET. So it is not subject to forms authentication.
In addition, we don't want ASP.NET to handle the request, because it uses up an ASP.NET thread and is not scalable for download of large files. So, configuring the asp.net dll to handle *.zip requests is not an option.
Any ideas on this?
One idea we've tossed around is this:
Initial request for download will be for an ashx handler. This handler will, after authentication, generate a download token which is saved to a database. Then, the user is redirected to the file with token appended in QueryString (e.g. /files/xyz.zip?token=123456789). An ISAPI plugin will be used to check the token. Also, the token will expire after x amount of time.
Any thoughts on this? I have not implemented an ISAPI plugin so I'm not sure if this will even work.
I would like to avoid custom coding since security is an issue and I'd prefer to use a time-tested solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
表单身份验证离不开 ASP.NET。
如果您根本不想使用 ASP.NET,您可以定义文件的 NTFS 权限并为您的用户创建域帐户。那很快就会变成一场噩梦。
要处理 ASP.NET 的大量下载,您可以查看 Comet。这基本上是一个
IHttpHandler
但您需要使用另一个 ThreadPool(不是 ASP.NET)。我建议查看智能线程池。几个月前,我将两者结合起来创建了一个用于下载速度限制的应用程序,现在运行得非常流畅。
Forms authentication can't go without ASP.NET.
If you don't want to use ASP.NET at all, you can define an NTFS permission on file and to create domain accounts to your users. That will become a nightmare really fast.
To deal with large downloads into ASP.NET, you can take a look into Comet. That's basically a
IHttpHandler
but you'll need to use another ThreadPool (not ASP.NET). I suggest take a look into Smart Thread Pool.I combined both a few months ago to create an application for download speed throttling and now runs very smoothly.
我阅读并理解您对使用处理程序来管理静态文件的担忧,但如果您使用异步处理程序,那么您将不会阻塞。
我认为您可能会以合理的价格获得您正在寻找的结果。
I read and understand your concern with using a handler to manage your static files, but if you use an async handler then you wont be blocking.
I think you might get the results you are looking for at a fair price.