在 ASP.NET 中通过 HttpModule 处理静态文件

发布于 2024-07-24 04:27:56 字数 410 浏览 5 评论 0原文

我的网站文件夹中有静态文件,但需要检查每个文件的权限。 我决定使用 HttpModule 来实现此目的。

ASP.NET 接收所有 http 请求(我使用通配符映射),

算法如下:

  1. HttpModule 接收请求
  2. HttpModule 检查权限
  3. 如果访问被拒绝,则答案为“禁止”。 如果一切正常,那么 httpModule 的方法就会返回。
  4. 自动使用DefaultHttpHandler处理静态文件的请求

问题是DefaultHttpHandler不够有效(它没有使用文件缓存等)。 但是 IIS(没有 ASP.NET)可以很好地处理静态文件。

我想要的只是让 IIS 在检查后提供静态文件。 有没有办法实现呢?

I have statiс files in website folder, but need to check permissions for every file.
I decided to use HttpModule for that purposes.

ASP.NET receives all the http-requests (I used wildcard mapping) and

The algorith is the following:

  1. HttpModule receives the request
  2. HttpModule checks permissions
  3. If access is denied then the answer is "Forbidden". If all is OK then httpModule's method just returns.
  4. DefaultHttpHandler is automatically used to process request for static files

The problem is that DefaultHttpHandler is not effective enough (it doesn't use file cache, etc.). But IIS (without ASP.NET) works with static files in a very good way.

All I want is to let IIS serve static files after my checks.
Is there any way to implement it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

西瑶 2024-07-31 04:27:56

如果您使用 IIS7,那么是的,这非常简单。 在集成模式下,所有请求都通过托管管道。 让 IIS 提供文件服务,但添加 HttpHandler 来执行检查。 或者您可以使用 ASP.NET 提供的授权方法之一。

If you're using IIS7 then yes, it's quite easy. In the integrated mode, all requests go through the managed pipeline. Let IIS serve the files, but add a HttpHandler to do the checks. Or you can use one of the authorization methods that ASP.NET offers.

电影里的梦 2024-07-31 04:27:56

我有一个可用于在 IIS 6 中流式传输文件的解决方案。它具有所有优点,例如可恢复下载、客户端缓存(etag 和过期)和服务器端缓存。

http://code.google.com/p/talifun-web/wiki/ StaticFileHandler

它应该很容易扩展以在提供文件之前包含授权。

I have a solution that could be used to stream the file in IIS 6. It does all the good things like resumable downloads, client side caching (etag & expires) and server side caching.

http://code.google.com/p/talifun-web/wiki/StaticFileHandler

It should be easy enough to extend to include authorization before serving up the file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文