在 ASP.NET 应用程序中使用 HttpHandler 可以进行哪些不同的自定义?
深入研究 HttpHandlers,我发现它们提供了自定义 ASP.NET 应用程序的好方法。我是 ASP.NET 新手,我想了解使用 HttpHandler 可以进行的不同自定义。许多网站都在讨论它们是如何实现的,但如果能够了解 ASP.NET 已经使用 HttpHandlers 提供的一些用例之外的一些用例,那就太好了。
Digging deeper into HttpHandlers I found they provide nice way to customize an ASP.NET application. I am new to ASP.NET and I want to know about different customizations that are possible using HttpHandlers. Lots of websites talk about how they are implemented but it would be nice to know some use cases beyond what ASP.NET already provides using HttpHandlers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ASPX 页面为基于表单的网页提供了基本模板(可以这么说)。默认情况下,它输出
text/html
并允许轻松添加表单元素以及这些元素的事件处理。相比之下,HttpHandler 被精简到只剩骨头。它就像 HTTP 请求的一张白纸。因此,HttpHandler 适用于许多不一定需要 Web 表单的请求类型。您可以使用 HttpHandler 输出动态图像、JSON 或许多其他 MIME 类型结果。
几个例子:
1) 您有一个页面需要进行 AJAX 调用,该调用将返回 JSON 响应。可以设置 HttpHandler 来处理此请求并输出 JSON。
2) 您有一个页面链接到作为二进制 blob 存储在数据库中的 PDF 文档。可以设置 HttpHandler 来处理此请求,并将二进制 blob 作为字节流输出,内容类型为 PDF MIME 类型。
An ASPX page provides a base template (so to speak) for a form-based web page. By default, it outputs
text/html
and allows for easy adding of form elements and event handling for these elements.In contrast, an HttpHandler is stripped to the bone. It is like a blank slate for HTTP requests. Therefore, an HttpHandler is good for many types of requests that do not necessarily require a web form. You could use an HttpHandler to output dynamic images, JSON, or many other MIME type results.
A couple examples:
1) You have a page which needs to make an AJAX call which will return a JSON response. An HttpHandler could be setup to handle this request and output the JSON.
2) You have a page which links to PDF documents that are stored as binary blobs in a database. An HttpHandler could be setup to handle this request and output the binary blob as a byte stream with a PDF MIME type for the content type.
检查此页面以获得一个很好的示例和代码,说明为什么您可能想要自定义它们:http://dotnetslackers.com/articles/aspnet/Range-Specific-Requests-in-ASP-NET.aspx 本质上,当您想要服务器某些文件但不允许它们时,可以使用它可通过普通 URL 访问(安全)。
Check this page for a good example and code of why you might want to customize them: http://dotnetslackers.com/articles/aspnet/Range-Specific-Requests-in-ASP-NET.aspx Essentially it can be used when you want to server certain files but not allow them to be accessible via a plain url (security).