【发布时间】:2013-11-02 02:33:56
【问题描述】:
我有一个用 IHttpHandler 用 c# 编写的简单处理程序。如何使它在 IIS 上工作?我按照http://mvolo.com/developing-iis7-modules-and-handlers-with-the-net-framework/#handler 中的教程进行操作,但它对我不起作用。
在 IIS7 中我的步骤:
我创建了一个名为“SAMPLE”的新网页
在 HandleMappings 中我按下了“添加托管处理程序”
我填写列 -> 请求路径:*.tm 类型:SampleServer.MyHandler 名称:MyHandler
尝试打开localhost/SampleServer.tm/
我收到此错误:MyHandler 模块列表中的“ManagedPipelineHandler”模块无效。 错误代码:0x8007000d
Web.сconfig 文件自动生成:
<?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()));
}
}
}
【问题讨论】:
-
@Kirk Woll 我编辑了我的帖子。我确定我在 IIS 配置中做错了什么。
-
如果您尝试不使用尾部斜杠会怎样:“localhost/SampleServer.tm”?
-
没有改变。它给出了同样的错误。
-
您在哪里看到该错误?你在事件日志中看到了什么有趣的东西吗?
-
对于可能的解决方案,它说: ASP.Net 未安装或配置不正确。并且还说“请确保您正确输入了模块名称”。我实际上认为向 IIS 添加处理程序时我的模块名称有问题。
标签: c# iis-7 ihttphandler