简体   繁体   中英

how to register a httphandler to handle all extensions in IIS?

I'm having trouble getting IIS 7 to load this handler I've written. I'm keeping things really simple to start with. I have a Handler.cs file with the following code in it:

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

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

I have put this file in the root directory.

I want to execute this code whenever the root directory receives a request, so I have built the handler file like this:

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

IIS gives me the following error when I attempt to go to localhost/runt (my website root directory )

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

Try setting the type to the fully qualified namesace.

You can find the default namespace through the properties of your web application.

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

I suspect that creating a default handler for everything using the .NET Framework will have some security risks and you should probably do further reading / consultation to make sure you aren't adversely putting your sites' security at risk.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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