您使用 ASP.Net 框架的哪一部分对 IIS 的每个入站请求执行任意代码?

发布于 2024-07-15 07:46:40 字数 291 浏览 4 评论 0原文

我想为 IIS 中某个网站发出的每个请求运行一段独立的 .Net 代码。 这是完全隔离的代码——它不会影响之前或之后的任何内容——它记录请求中的一些信息,然后结束。

请注意,这不是我可以放入 Application_OnRequestBegin 或其他 ASP.Net 文件中的内容,因为我需要它来执行非 .Net 文件(PDF、图像等)。 它需要执行通常不会到达 .Net 框架的请求。

我正在寻找 HTTP 模块吗? 我已经做过很多 RTFM 了,但似乎有很多不同的方法来操纵管道,而且我不太确定应该使用哪一种。

I'd like to run a discrete chunk of .Net code for each and every request that comes through a certain Web site in IIS. This is completely isolated code -- it doesn't affect anything before or after it -- it logs some information from the request, then ends.

Note that this is not something I can put in Application_OnRequestBegin or some other ASP.Net file because I need this to execute for non .Net files (PDFs, images, etc.). It needs to execute for requests that would normally not hit the .Net framework.

Is an HTTP Module what I'm looking for? I've RTFM'ed quite a bit, but it seems there a number of different ways to manipulate the pipeline, and I'm not quite sure which one I should be using.

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

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

发布评论

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

评论(2

任谁 2024-07-22 07:46:40

您可以使用 HTTP 模块,但是,要使用它,您将需要将所有请求映射到 IIS,这可以使用 通配符映射。。 这将对性能产生影响,因为您将强制所有请求通过 .net 运行时。

您也可以编写自己的 ISAPI 过滤器,但我相信您必须使用 C++。

编辑

ASP.Net 有一个默认处理程序,如果您执行所需的通配符映射,请确保您的 windows/microsoft.net/framework..../config/ 文件夹中的 web.config 中仍然有此处理程序:

<httpHandlers>
....
            <add path="*" verb="GET,HEAD,POST" type="System.Web.DefaultHttpHandler" validate="True"/>
</httpHandlers>

您可能有还删除了网络配置文件中的处理程序。 最后,您可以尝试为 pdf 文件添加显式映射。

You can use an HTTP Module, however, to use it you will need to map all requests to IIS which can be done using a wild card map.. This will have a performance impact because you're going to be forcing all requests through the .net runtime.

You could also write your own ISAPI filter, but I believe you'll have to use C++.

Edit

ASP.Net has a default handler if your doign the wild card mapping you need, make sure you still have this in your web.config in your windows/microsoft.net/framework..../config/ folder:

<httpHandlers>
....
            <add path="*" verb="GET,HEAD,POST" type="System.Web.DefaultHttpHandler" validate="True"/>
</httpHandlers>

You might have also removed the handler in your web's config file. Lastly you could try and add an explicit mapping for the pdf file.

小忆控 2024-07-22 07:46:40

您想要编写一个 ISAPI 过滤器(5.0 术语)或扩展(6.0 中)。

You want to write an ISAPI filter (5.0 terminology), or extension (in 6.0).

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