我无法让 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