【问题标题】:Custom HTTP handler configuration fail自定义 HTTP 处理程序配置失败
【发布时间】:2013-01-21 13:57:06
【问题描述】:

我正在开发一个 ASP .Net 网站。 我创建了一个自定义 HTTP 处理程序来响应针对具有 .videoImage 扩展名的资源的请求。
这是与我的处理程序对应的文件的第一行:

<%@ WebHandler Language="C#" Class="CompleteSubtitles.VideoImage" %>

using System;
using System.Web;
using System.IO;
using SubtitleSounds.DataManagement;

namespace CompleteSubtitles
{
    public class VideoImage : IHttpHandler
    {
        ...
    }
}

处理程序文件位于网站根文件夹的子文件夹中。
我在我的网站根 web.config 文件中配置了我的处理程序,如下所示:

<configuration>
    <system.web>
        ...

        <httpHandlers>
          <add verb="*" path="*.videoImage" type="CompleteSubtitles.VideoImage" />
        </httpHandlers>
    </system.web>
</configuration>

我在加载页面时收到一条 ASP .Net 错误消息,通知我 CompleteSubtitles.VideoImage 类型的加载失败。
有谁知道为什么?
任何帮助将不胜感激。

【问题讨论】:

  • 在“类型”属性中,您需要提供程序集名称,然后为您的案例键入名称可能像这样type="CompleteSubtitles, CompleteSubtitles.VideoImage"

标签: asp.net web-config httphandler


【解决方案1】:

没有确切的错误消息我无法确定,但根据我在处理程序和 Web 表单方面的经验,这是可行的:

  • 你的 Handler 不能是一个简单的 VB/CS 文件,即使你把它放在 APP_CODE 文件夹中(从来没有和我一起工作过)。您需要放置在 DLL 中,我总是为此使用单独的类库。

  • 如果主机使用IIS 7,system.web/httpHandlers不起作用,需要添加system.webServer。我两个都留着以防万一。这是一个示例(bNet.Ferramentas 是我的 DLL 文件):

>

<system.web>
    <httpHandlers>
        <add verb="*" path="sitemap.ashx" type="bNet.Ferramentas.SiteMapHandler, bNet.Ferramentas" />
    </httpHandlers>
</system.web >


<system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <handlers>
        <add verb="*" name="bnetSitemap" path="sitemap.ashx" type="bNet.Ferramentas.SiteMapHandler, bNet.Ferramentas"/>
    </handlers>
</system.webServer>

【讨论】:

    【解决方案2】:

    您必须指定类的全名(HttpHanlder),如下所示:

     <configuration> 
     <system.webServer>
     <handlers> 
        <add verb="*" path="*.sample" name="HelloWorldHandler" type="HelloWorldHandler"/>
     </handlers>
     </system.webServer>
     </configuration>
    

    了解更多click here

    希望它会有所帮助。

    【讨论】:

      【解决方案3】:

      这是我解决问题的方法:
      我在 App_Code 文件夹中创建了一个代表我的处理程序的类。
      我的处理程序文件的扩展名是“.cs”而不是“.ashx”。
      我的处理程序在我的 web.config 中的声明是:

      <httpHandlers>
        <add verb="*" path="*.videoImage" type="CompleteSubtitles.VideoImageHandler" />
      </httpHandlers>
      

      【讨论】:

        猜你喜欢
        • 2014-07-14
        • 1970-01-01
        • 2015-06-23
        • 2010-10-20
        • 2011-05-04
        • 2012-10-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多