locked
This HttpHandler doesn't map files...please help RRS feed

  • Question

  • User1246607441 posted
    Hi all, I've a problem. I want to make a HttpHandler that intercepts file requests. I made a HttpHandler that looks like this: Public Class FileProtector Implements IHttpHandler Public Sub ProcessRequest(ByVal objContext As HttpContext) Implements IHttpHandler.ProcessRequest Dim strPath As String Dim strExtension As String strPath = objContext.Request.Path strExtension = GetFileExtension(strPath) Select Case UCase(strExtension) Case ".HOWDY" objContext.Response.Write("You're not allowed to download HOWDY files!") Case ".HELLO" objContext.Response.Write("Don't touch our HELLO files!") End Select objContext.Response.Write("U heeft geen toegang tot bestand " & strPath & " met extensie " & strExtension & "") End Sub Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable Get Return True End Get End Property Private Function GetFileExtension(ByVal strParamFile As String) As String Dim strReturnValue As String = "" Dim objFileInfo As New FileInfo(strParamFile) strReturnValue = objFileInfo.Extension objFileInfo = Nothing Return strReturnValue End Function End Class I've put these lines to my Web.config: <httpHandlers> <add verb=".HOWDY" path="*" type="HandlerClass,HandlerClass" /> <add verb=".HELLO" path="*" type="HandlerClass,HandlerClass" /> </httpHandlers> I can't get the bloody thing to intercept a .HOWDY or .HELLO file request. I get a "The Page Cannot Be Found" message when I enter an address like http://localhost/MyApp/AtestFile.HOWDY Can you guys help me with this?? Thanks very much!:-D Ben.
    Friday, February 27, 2004 8:40 AM

All replies

  • User-1372641848 posted
    you will need to tell IIS about those extension and map it to aspnet_isapi.dll. If we don't perform this step IIS will try to return actual file(which i suppose is not present on server) rather then passing request to ASP.NET runtime. As a result, the HTTP handler will not be called. Launch the Internet Services Manager tool, right click on Web Site, select Properties, go to Home Directory tab and press Configuration button. This will popup Application Configuration dialog. Click Add button and fill the Executable field with the path to the aspnet_isapi.dll file and fill .HELLO in the Extension field. (you can copy settings for .aspx extension)
    Friday, February 27, 2004 9:22 AM
  • User1246607441 posted
    Hi, Thanks for your reply! So I can't do this without doing stuff with te IIS tools? But can I pull off this trick with extensions knownto IIS and without tinckering with the IIS tools? Let's say I try to download http://localhost/MyApp/products.xml Can I use the handler to intercept this request so the downloader won't be able to grab this file? Thanks for any help. Greetz, Ben
    Friday, February 27, 2004 9:52 AM
  • User-1372641848 posted
    If .xml is mapped to aspnet_isapi.dll in IIS and you add following(its different from way you were writing) to web.config file <httpHandlers> <add verb="*" path="*.xml" type="HandlerClass,HandlerClass"/> </httpHandlers> it should work. But by .XML Extension is not mapped with any thing in IIS PS: IIS 6 Allows ".*" mapping so every request on your server will go through aspnet_isapi.dll.
    Friday, February 27, 2004 10:14 AM
  • User-1049946619 posted
    Ben, Look at the lines from your web.config: <httpHandlers> <add verb=".HOWDY" path="*" type="HandlerClass,HandlerClass" /> <add verb=".HELLO" path="*" type="HandlerClass,HandlerClass" /> </httpHandlers> They are backwards. The verb is the HTTP verb, for example, PUT, GET, etc. (or * for all verbs), and the path is where you set up your filename extension. Also, if your HttpHandler is in another assembly, you are missing the assembly name of your handler; and, if not, the portion after the comma should not be the same as your base assembly. In other words, if your handler is in an assembly called HandlerAssembly (compiled into HandlerAssembly.dll) it should look like this: <httpHandlers> <add verb="*" path="*.HOWDY" type="HandlerAssembly.HandlerClass,HandlerAssembly" /> <add verb="*" path="*.HELLO" type="HandlerAssembly.HandlerClass,HandlerAssembly" /> </httpHandlers> The other person was correct; you would ordinarily open Internet Services Manager and create a mapping for your extension(s) in the virtual directory where your app resides. See this article for more info: http://support.microsoft.com/default.aspx?scid=kb;EN-US;30799#3 However, it seems like it is possible under some circumstances to use an HttpHandler without creating such a mapping (using an existing mapping). I'll address this, though, in a separate post.
    Sunday, February 29, 2004 2:26 PM