通过ASP.NET中的HttpModule处理静态文件 [英] Processing static files via HttpModule in ASP.NET

查看:759
本文介绍了通过ASP.NET中的HttpModule处理静态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网站文件夹中有statiс文件,但需要检查每个文件的权限。
我决定将HttpModule用于此目的。

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接收所有http请求(我使用通配符映射)和

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

算法是以下:


  1. HttpModule收到请求

  2. HttpModule检查权限

  3. 如果拒绝访问,则答案为禁止访问。如果一切正常,那么httpModule的方法就会返回。

  4. DefaultHttpHandler自动用于处理静态文件的请求

  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

问题是DefaultHttpHandler不够有效(它不使用文件缓存等)。但IIS(没有ASP.NET)以非常好的方式使用静态文件。

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.

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

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

推荐答案

如果你正在使用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.

这篇关于通过ASP.NET中的HttpModule处理静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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