繁体   English   中英

如何注册一个httphandler以处理IIS中的所有扩展?

[英]how to register a httphandler to handle all extensions in IIS?

我无法让IIS 7加载我编写的此处理程序。 我让事情从一开始就很简单。 我有一个Handler.cs文件,其中包含以下代码:

public class Handler :IHttpHandler
{
    public bool IsReusable
    {
        get { return false; }
    }

    public void ProcessRequest(HttpContext context)
    {
        context.Response.Write("asdfasdf"); 
    }
}

我已将此文件放在根目录中。

每当根目录收到请求时,我都想执行此代码,因此我已经建立了如下处理程序文件:

<configuration>
  <system.webServer>
    <handlers>
      <add name="Handler" verb="*" 
        path="*.*" 
        type="Handler" 
        resourceType="Unspecified" />
    </handlers>
  </system.webServer>
</configuration>

当我尝试转到localhost / runt(我的网站根目录)时,IIS给我以下错误

Server Error in '/' Application.

Could not load type 'Handler'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: Could not load type 'Handler'.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[HttpException (0x80004005): Could not load type 'Handler'.]
   System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +11247344
   System.Web.Configuration.HandlerFactoryCache.GetHandlerType(String type) +23
   System.Web.Configuration.HandlerFactoryCache..ctor(String type) +25
   System.Web.HttpApplication.GetFactory(String type) +91
   System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +338
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +263

Version Information: Microsoft .NET Framework Version:2.0.50727.5466; ASP.NET Version:2.0.50727.5459

尝试将类型设置为完全限定的名称。

您可以通过Web应用程序的属性找到默认名称空间。

<configuration>
  <system.webServer>
    <handlers>
      <add name="Handler" verb="*" 
        path="*.*" 
        type="DefaultNamspaceFromProperties.ClassNamespace.Handler" 
        resourceType="Unspecified" />
    </handlers>
  </system.webServer>
</configuration>

我怀疑使用.NET Framework为所有内容创建默认处理程序会带来一些安全风险,因此您可能应该做进一步的阅读/咨询,以确保不会对站点的安全性造成不利影响。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM