Search code examples
asp.netiishttphandlervirtual-directory

HttpHandler to protect files in a virtual directory


My goal is to protect certain files that exist inside a virtual directory of my ASP.NET web forms application. To accomplish this I have an HTTPHandler called "FileAccessHandler". In my web.config I have tried setting the "path" to the virtual directory, however it seems to only work on paths that exist within my application and not the virtual directory. I get the following error when using a virtual directory path: "Could not load type MyProject.FileAccessHandler".

I have the handler configuration as follows:

    <system.webServer>
      <httpModules>
        <add name="FileAccessHandler" path="/attachments/*" verb="*" type="MyProject.FileAccessHandler" resourceType="File" preCondition="integratedMode"/>
      </handlers>
    </system.webServer>

I have tried manually adding the HTTP Handler through IIS directly to the virtual directory with no luck as well. Any help would be greatly appreciated!!


Solution

  • Issue Found! The virtual directory had been converted to an Application, therefore the HTTPHandler type was not recognized from a nested application.

    This website was previously installed on an IIS 6 web server where the ASP environment was more forgiving and the same icon was used for both cases. Once it was converted to a virtual directory the HTTP Handler type was recognized.

    More Info:

    http://forums.asp.net/t/1813828.aspx?adding+virtual+directory+vs+convert+to+application+