Custom HTTP handler configuration fail

落花浮王杯 提交于 2019-12-13 06:27:14

问题


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.


回答1:


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>




回答2:


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:


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>


来源:https://stackoverflow.com/questions/14727886/custom-http-handler-configuration-fail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!