IHttpHandler 与 IHttpModule [英] IHttpHandler vs IHttpModule

查看:33
本文介绍了IHttpHandler 与 IHttpModule的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很简单(尽管答案很可能不是):我正在尝试决定如何在 C#/ASP.NET 中实现服务器端上传处理程序.

My question is simple (although the answer will most likely not be): I'm trying to decide how to implement a server side upload handler in C# / ASP.NET.

我使用过 HttpModules(IHttpModule 接口)和 HttpHandlers(IHttpHandler 接口),我发现我可以使用任何一种机制来实现它.我也发现我不明白两者之间的区别.

I've used both HttpModules (IHttpModule interface) and HttpHandlers (IHttpHandler interface) and it occurs to me that I could implement this using either mechanism. It also occurs to me that I don't understand the differences between the two.

所以我的问题是:在什么情况下我会选择使用 IHttpHandler 而不是 IHttpModule(反之亦然)?

在管道中执行得更高吗?在某些情况下是否更容易配置?在中等安全性下工作不好吗?

推荐答案

ASP.NET HTTP 处理程序 是响应请求而运行的进程(通常称为端点")用于 ASP.NET Web 应用程序.最常见的处理程序是处理 .aspx 文件的 ASP.NET 页处理程序.当用户请求 .aspx 文件时,该请求由页面通过页面处理程序处理.您可以创建自己的 HTTP 处理程序,将自定义输出呈现给浏览器.

An ASP.NET HTTP handler is the process (frequently referred to as the "endpoint") that runs in response to a request made to an ASP.NET Web application. The most common handler is an ASP.NET page handler that processes .aspx files. When users request an .aspx file, the request is processed by the page through the page handler. You can create your own HTTP handlers that render custom output to the browser.

自定义 HTTP 处理程序的典型用途包括:

Typical uses for custom HTTP handlers include the following:

  • RSS 提要 要为网站创建 RSS 提要,您可以创建一个处理程序来发出 RSS 格式的 XML.然后,您可以将文件扩展名(例如 .rss)绑定到自定义处理程序.当用户向您的网站发送以 .rss 结尾的请求时,ASP.NET 会调用您的处理程序来处理该请求.
  • 图像服务器 如果您希望 Web 应用程序提供各种尺寸的图像,您可以编写一个自定义处理程序来调整图像大小,然后将它们作为处理程序的响应发送给用户.

HTTP 模块 是一个程序集,在向您的应用程序发出的每个请求上都会调用它.HTTP 模块作为 ASP.NET 请求管道的一部分被调用,并且可以访问整个请求中的生命周期事件.HTTP 模块可让您检查传入和传出的请求并根据请求采取行动.

An HTTP module is an assembly that is called on every request that is made to your application. HTTP modules are called as part of the ASP.NET request pipeline and have access to life-cycle events throughout the request. HTTP modules let you examine incoming and outgoing requests and take action based on the request.

HTTP 模块的典型用途包括:

Typical uses for HTTP modules include the following:

  • 安全性 因为您可以检查传入的请求,所以 HTTP 模块可以在调用请求的页面、XML Web 服务或处理程序之前执行自定义身份验证或其他安全检查.在以集成模式运行的 Internet 信息服务 (IIS) 7.0 中,您可以将表单身份验证扩展到应用程序中的所有内容类型.
  • 统计和日志记录 因为 HTTP 模块会在每个请求上被调用,所以您可以在一个集中的模块中而不是在单个页面中收集请求统计信息和日志信息.
  • 自定义页眉或页脚 因为您可以修改传出响应,所以您可以将自定义页眉信息等内容插入到每个页面或 XML Web 服务响应中.

来自:http://msdn.microsoft.com/en-us/图书馆/bb398986.aspx

这篇关于IHttpHandler 与 IHttpModule的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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