Setting the MIME file type from web.config
I have a temporary directory at:
c:\inetpub\mysite\temp\
I am building a text file dynamically and saving it in this directory. Then I have the users browser loading this file by putting it in an iframe. This works great for files the browser cannot open (.doc, .zip), but since I am using a TXT file, the browser just opens it. for example It never goes through the normal download process where you can choose where you want to download it.
A little research and I found that you can put the web.config file in the same directory as the file to configure the HTTP headers and then do something like:
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".txt" mimeType="application/octet-stream" />
</staticContent>
</system.webServer>
</configuration>
But when I do this, I get Cannot add duplicate collection entry of type 'mimeMap' with unique key attribute 'fileExtension' set to '.txt'
. So I am assuming that the .txt MIME type is already set at the parent level in the web.config.
Is there a way to set the MIME type for static content in a sheet directory (or for a specific directory) using a web.congig file?
I found it . You must remove the other before adding.
<configuration>
<system.webServer>
<staticContent>
<remove fileExtension=".txt" />
<mimeMap fileExtension=".txt" mimeType="application/octet-stream" />
</staticContent>
</system.webServer>
</configuration>