4

I need to convert .htaccess

AddType application/x-httpd-php .txt

to web.config. Could you help me with it? I tried

    <configuration>
  <system.web>
    <httpHandlers>
      <add verb="*" path="*.txt" 
         type="php " />
    </httpHandlers>
  </system.web>
</configuration>

but it doesn't work for me. So at all I need to open txt files like php on IIS.

Andrej
  • 77
  • 1
  • 6
  • It will not work as simple as that. Of course, you can create custom handler mapping, but for that you need to know all the details how that particular handler is defined (basically, you need to make the same entry as for php but for txt files). Quite possible that such config operation will be prohibited at web.config level (can only be created on upper/system-wide level -- all depends on server settings --> feature Delegation). The most reliable solution (that would work on almost all servers) is to create URL rewrite rule and have some small script that will process those txt files as php. – LazyOne May 30 '12 at 13:30
  • If you have full control over IIS, then just launch IIS Manager, find your site (if it is site-specific entry), choose Handler Mappings and see how handler for php files is declared. Then do the same but for *.txt files. For example: `` (located in C:\Windows\System32\inetsrv\config\applicationHost.config) – LazyOne May 30 '12 at 13:31
  • No, I don't have full control over IIS. So there are no other ways to do it? – Andrej May 30 '12 at 16:03
  • By default Handler Mappings is not allowed to be modified in web.config. To allow such modification you have to control IIS via Feature Delegation functionality (change state from "Read-Only" to "Read/Write"). If you cannot do that -- then URL Rewrite approach is the best (if not the only one) solution for you. – LazyOne May 30 '12 at 16:10

1 Answers1

2

This works for me:

<configuration>
   <system.webServer>
      <staticContent>
         <mimeMap fileExtension=".syx" mimeType="application/octet-stream" />
         <mimeMap fileExtension=".tab" mimeType="text/plain" />
      </staticContent>
   </system.webServer>
</configuration>

Source: http://www.iis.net/configreference/system.webserver/staticcontent/mimemap

Ruslan
  • 21
  • 2