如何将IHttpHandler代码部署到IIS

时间:2013-11-02 02:33:56

标签: c# iis-7 ihttphandler

我有一个用IHttpHandler用c#编写的简单处理程序。如何让它在IIS上运行?我按照http://mvolo.com/developing-iis7-modules-and-handlers-with-the-net-framework/#handler中的教程进行了操作,但它对我不起作用。

在IIS7中我的步骤:

  1. 我创建了一个名为“SAMPLE”的新网页

  2. 从HandleMappings我按下了“添加管理处理程序”

  3. 我填写列 - >请求路径:* .tm类型:SampleServer.MyHandler名称:MyHandler

  4. 尝试打开localhost / SampleServer.tm /

  5. 我收到此错误:MyHandler模​​块列表中的“ManagedPipelineHandler”模块无效。 错误代码:0x8007000d

    Web.сonfig文件自动生成:

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <handlers>
                <add name="MyHandler" path="*.tm" verb="*" type="SampleServer.MyHandler" resourceType="Unspecified" preCondition="integratedMode" />
            </handlers>
        </system.webServer>
    </configuration>
    

    我的handler.cs文件:

    namespace SampleServer
    {
        class MyHandler : IHttpHandler
        {
            public bool IsReusable
            {
                get { return false; }
            }
    
            public void ProcessRequest(HttpContext context)
            {
                DateTime dt = DateTime.Now;
                context.Response.Write(String.Format("<h1>{0}</h1>", dt.ToLongTimeString()));
            }
        }
    }
    

1 个答案:

答案 0 :(得分:0)

终于找到了答案。这是因为我删除了以前的IIS并安装了IIS7。 IIS需要配置.NET库。

在cmd:

上运行此命令
    "%windir%\Microsoft.NET\Framework\"YOUR .NET VERSION"\aspnet_regiis.exe" -i

然后,如果您的网站的.NET版本低于* .dll文件的版本,请从应用程序池中更改它。之后它运作良好。

相关问题