.NET code for creating IIS mapping

  • Thread starter Thread starter Alexander Rudyk
  • Start date Start date
A

Alexander Rudyk

Hi all.

I need in my MSI custom action create IIS mapping for given virtual
directory.
For example, assosiate txt file extension with ASP.NET ISAPI to deny access
to txt file from IE.

Maybe someone have example code or links to such code.

Thanks
 
I am not sure I understand. If you want to handle specific extensions
explicitly, check out the <httpHandlers> documentation for web.config. You
will need to provide the path and the type. For the example you have given,
it might look something to the effect of
<system.web>
<httpHandlers>
<add path="*.txt" type="System.Web.HttpForbiddenHandler"/>
</httpHandlers>
....
</system.web>
...
in your web.config.
 
<add path="*.txt" type="System.Web.HttpForbiddenHandler"/>
</httpHandlers>

This handler works if the user request to some.txt file inside virtual dir
redirected to aspnet_isapi.dll. Only in this case this handler works. But
requests to *.txt files by default dose not redirected to any ISAPI
extension
and thus file content displayed by IE. To redirect requests to txt file to
ASP.NET runtime to I need add IIS mapping "*.txt -> aspnet_isapi.dll"

Main problem how can I do this by program code?
 
I doubt if you can. Unless, you write your own ISAPI or a similar handler at
the IIS level, I dont know if you can do that from ASP.NET code.
 
Back
Top