Custom HTTP handler configuration fail

2019-08-28 23:31发布

I am developing an ASP .Net website. I have created a custom HTTP handler to respond to requests aiming resources with .videoImage extension.
Here are the first lines of the file corresponding to my handler :

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

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

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

The handler file is located in a subfolder of the website root folder.
I have configured my handler in my website root web.config file as follows :

<configuration>
    <system.web>
        ...

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

I have got an ASP .Net error message when loading a page informing me that the loading of CompleteSubtitles.VideoImage type failed.
Does anyone know why ?
Any help will be greatly appreciated.

3条回答
一夜七次
2楼-- · 2019-08-28 23:34

you have to specify the full name of the class (HttpHanlder) as follows:

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

For more click here

Hope it will help.

查看更多
欢心
3楼-- · 2019-08-28 23:42

Whitout the exact error message I can't be sure, but when from my experience with handlers and Web Forms, this works:

  • Your Handler can't be a simple VB/CS file, even if you place it on APP_CODE folder (never worked with me). You need place in a DLL, I always use a separate Class Library for that.

  • If the host uses IIS 7, system.web/httpHandlers don't work, you need to add system.webServer. I keep both just in case. Here is a sample (bNet.Ferramentas is my DLL file):

>

<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>

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-08-28 23:45

Here is how I have solved my problem :
I have created a class representing my handler in my App_Code folder.
My handler file's extension is ".cs" and not ".ashx".
The declaration of my handler in my web.config is :

<httpHandlers>
  <add verb="*" path="*.videoImage" type="CompleteSubtitles.VideoImageHandler" />
</httpHandlers>
查看更多
登录 后发表回答