惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 三生石上(FineUI控件)
Hugging Face - Blog
Hugging Face - Blog
M
MIT News - Artificial intelligence
T
Tailwind CSS Blog
Webroot Blog
Webroot Blog
S
Secure Thoughts
N
News and Events Feed by Topic
月光博客
月光博客
TaoSecurity Blog
TaoSecurity Blog
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog RSS Feed
N
News | PayPal Newsroom
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
小众软件
小众软件
Recent Commits to openclaw:main
Recent Commits to openclaw:main
P
Privacy & Cybersecurity Law Blog
GbyAI
GbyAI
K
Kaspersky official blog
WordPress大学
WordPress大学
P
Proofpoint News Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
博客园 - 叶小钗
W
WeLiveSecurity
Jina AI
Jina AI
The Cloudflare Blog
Project Zero
Project Zero
Simon Willison's Weblog
Simon Willison's Weblog
V
Vulnerabilities – Threatpost
L
LangChain Blog
Forbes - Security
Forbes - Security
PCI Perspectives
PCI Perspectives
Engineering at Meta
Engineering at Meta
Google DeepMind News
Google DeepMind News
Recorded Future
Recorded Future
博客园 - 【当耐特】
H
Heimdal Security Blog
A
About on SuperTechFans
Cisco Talos Blog
Cisco Talos Blog
T
Threat Research - Cisco Blogs
云风的 BLOG
云风的 BLOG
Spread Privacy
Spread Privacy
L
LINUX DO - 最新话题
L
Lohrmann on Cybersecurity
Last Week in AI
Last Week in AI
Google DeepMind News
Google DeepMind News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
I
Intezer
Martin Fowler
Martin Fowler
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint

博客园 - Laeb

ASP.NET Web 页面语法概览 ASP.NET Web 页面中的新事物 渐增的许可 介绍 ASP.NET Web 页面 管理工具 ASP.NET Web 页面概览 检测何时需要更改安全策略 安全策略管理的概览 System.Net 类的最佳习惯 异常处理的最佳习惯 面向世界应用程序开发的最佳习惯 使用 ASP.NET 所创建的 XML Web 服务的设计指南 为并发执行而创建应用程序与组件的指南 ASP.NET 控件与可访问 ASP.NET 中的可访问支持 实践:创建自定义 HTTP 模块 HTTP 模块介绍 实践:创建 HTTP 处理器工厂 实践:创建同步 HTTP 处理器
实践:注册 HTTP 处理器
Laeb · 2007-03-17 · via 博客园 - Laeb

在你创建自定义的 HTTP 处理器类之后,你就必须把它注册到 Web.config 文件中。这允许 ASP.NET 调用该处理器来服务于你需要该 HTTP 服务器进行处理并且拥有特定文件扩展名的资源请求。

在 Web.config 文件中注册 HTTP 处理器

如果要让 ASP.NET 把请求发送到自定义的 HTTP 处理器,你就必须使用自定义 HTTP 处理器来注册特定的文件扩展名。你可以在应用程序的 Web.config 文件中完成这个任务。

注册 HTTP 处理器
  1. 编译 HTTP 处理器的 .NET 类并且把结果汇编集复制到应用程序虚拟根目录下的 Bin 目录中,或者把处理器的源代码存放到应用程序的 App_Code 目录中。

    关于 HTTP 处理器的范例,请参考:[实践:创建同步 HTTP 处理器]。

  2. 你可以在应用程序的 Web.config 文件中创建一个 httpHandlers 元素(ASP.NET 设置结构)配置段来注册 HTTP 处理器。

    下列代码说明了如何注册一个对资源 SampleHandler.new 的请求产生回应的 HTTP 处理器。该处理器被定义成汇编集 SampleHandlerAssembly 中的 SampleHandler 类。

    <configuration>
      <system.web>
        <httpHandlers>
          <add verb="*" path="SampleHandler.new" 
            type="SampleHandler, SampleHandlerAssembly" />
        </httpHandlers>
      <system.web>
    </configuration>

    下列代码把所有对于扩展名是 SampleFileExtension 的文件的 HTTP 请求都映射到自定义 HTTP 处理器类 SampleHandler2 中。在这种情况下的处理器代码应该位于 App_Code 目录中,因此你不需要指定任何汇编集。

    <configuration>
      <system.web>
        <httpHandlers>
          <add verb="*" path="*.SampleFileExtension" 
             type="SampleHandler2 " />
        </httpHandlers>
      <system.web>
    </configuration>

配置 IIS 的 HTTP 处理器扩展

Internet Information Services(IIS)只会把特定文件类型的请求传递给 ASP.NET 的服务。默认时,拥有文件扩展名 .aspx、.ascx、.asmx 和 .ashx 的文件都已经被映射到了 ASP.NET ISAPI 扩展(Aspnet_isapi.dll)中。因此,如果要让 IIS 把自定义的文件扩展名传递给 ASP.NET,你就必须在 IIS 中注册这些扩展名。关于更多信息,请参考:[ASP.NET 应用程序生命周期概览]。

在 IIS 中映射文件扩展名
  1. 在 Windows 中,打开 Internet Information Services(IIS)Manager。
  2. 打开本地计算机节点,打开 Web Sites 节点,然后打开 Default Web Site 节点。
  3. 右击应用程序的名称,然后点击 Properties。
  4. 点击 Directory 制表页(或者是 IIS 6.0 中的 Virtual Directory 制表页),然后点击 Configuration。
  5. 在 Mappings 制表页中,点击 Add 并且为你需要 IIS 转发给 ASP.NET 的文件扩展名创建一个新的关联。

    提示:点击 Edit 按钮可以查看现有的关联来检测可执行文件所使用的值。

  6. 如果你需要你的处理器在运行的时候忽略已请求的文件扩展名是否已经存在,那么就可以清除 Verify that file exists 复选框。