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: 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.
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)
Jigar Desai -----------------------
Do not forget to "Mark as Answer" on the post that helped you.
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
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 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.
Jigar Desai -----------------------
Do not forget to "Mark as Answer" on the post that helped you.
Ben, Look at the lines from your web.config: 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: 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.
BenjaminHusm...
Member
20 Points
4 Posts
This HttpHandler doesn't map files...please help
Feb 27, 2004 12:40 PM|LINK
Jigar
Contributor
4629 Points
935 Posts
Have you mapped those extension with IIS?
Feb 27, 2004 01:22 PM|LINK
-----------------------
Do not forget to "Mark as Answer" on the post that helped you.
BenjaminHusm...
Member
20 Points
4 Posts
Re: Have you mapped those extension with IIS?
Feb 27, 2004 01:52 PM|LINK
Jigar
Contributor
4629 Points
935 Posts
If .xml is mapped to aspnet_isapi.dll in IIS then YES
Feb 27, 2004 02:14 PM|LINK
-----------------------
Do not forget to "Mark as Answer" on the post that helped you.
DonYeske
Member
135 Points
27 Posts
Re: This HttpHandler doesn't map files...please help
Feb 29, 2004 06:26 PM|LINK