ASP.NET 网站中自定义 HttpHandler 出现错误 500(IIS 7.5、Win7)

发布于 2024-09-16 09:26:15 字数 1384 浏览 8 评论 0原文

我正在尝试让自定义 HttpHandler 在我的示例 Web 应用程序中工作。我遇到了很多问题,但最终遇到了错误 500。应用程序池正在经典 ASP.NET 2.0 模式下运行。服务器是IIS 7.5,操作系统是Win 7 Pro。

这是我的处理程序的代码:

public class SampleHandler : IHttpHandler
{
    public SampleHandler()
    {

    }

    public bool IsReusable 
    {
        get 
        {
            return true;
        }
    }

    public void ProcessRequest(HttpContext context) 
    {
        context.Response.Clear();
        context.Response.ContentType = "text/html";
        context.Response.Write("This is a sample content.");
        context.Response.Expires = 0;
        context.Response.End();
    }
}

这是 web.config 文件内容:

<?xml version="1.0"?>

<configuration>
  <system.web>
    <httpHandlers>
      <add verb="*" path="*.shc" type="SampleHandler"/>
    </httpHandlers>
  </system.web>
  <system.webServer>
    <handlers>
      <add resourceType="Unspecified" verb="*" path="*.shc" name="SampleHandler" type="SampleHandler" modules="IsapiModule" scriptProcessor="c:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll\aspnet_isapi.dll"/>
    </handlers>
  </system.webServer>
</configuration>

这是错误屏幕截图的链接: http ://bit.ly/cmPk4i

有人可以告诉我我做错了什么吗?提前致谢!

I'm trying to get custom HttpHandler working in my sample web application. I've been experiencing a lot of issues, but finally got stuck with error 500. Application pool is being run in Classic ASP.NET 2.0 mode. Server is IIS 7.5, OS is Win 7 Pro.

Here's a code of my handler:

public class SampleHandler : IHttpHandler
{
    public SampleHandler()
    {

    }

    public bool IsReusable 
    {
        get 
        {
            return true;
        }
    }

    public void ProcessRequest(HttpContext context) 
    {
        context.Response.Clear();
        context.Response.ContentType = "text/html";
        context.Response.Write("This is a sample content.");
        context.Response.Expires = 0;
        context.Response.End();
    }
}

Here is a web.config file content:

<?xml version="1.0"?>

<configuration>
  <system.web>
    <httpHandlers>
      <add verb="*" path="*.shc" type="SampleHandler"/>
    </httpHandlers>
  </system.web>
  <system.webServer>
    <handlers>
      <add resourceType="Unspecified" verb="*" path="*.shc" name="SampleHandler" type="SampleHandler" modules="IsapiModule" scriptProcessor="c:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll\aspnet_isapi.dll"/>
    </handlers>
  </system.webServer>
</configuration>

Here is a link to the screenshot of an error : http://bit.ly/cmPk4i

Could anybody please tell me what I did wrong? Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜妞爱困 2024-09-23 09:26:15

中设置

尝试在

我遇到了 500 错误,这解决了它。

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
        <add .... />
    </handlers>
</system.webServer>

Try setting

<validation validateIntegratedModeConfiguration="false" />

in

<system.webServer>

I had 500 error and this fixed it.

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
        <add .... />
    </handlers>
</system.webServer>
我ぃ本無心為│何有愛 2024-09-23 09:26:15

从“您可以尝试的事情”列表中,您是否安装了 .Net 可扩展性功能?

您还可以在应用程序上启用失败请求日志记录功能,该功能提供有关请求处理的详细信息。

至少,好消息是您注册的处理程序被识别为要执行的处理程序。

From the list of "things you can try", did you install the .Net Extensibility Feature?

You can also enable the Failed Requests logging feature on the application, which provides detailed information on request processing.

The good news, at least, is that your registered handler is recognized as the handler to be executed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文