Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS: How to serve a file without extension?

Tags:

iis

iis-10

iis-8

I am using IIS 8 on Windows 8.1. I have an XML file an I need to have it accessed through (servername)/(path)

(path) is predefined by someone else and does not contain an extension. I tried the simple solution of removing the .xml file the file name, but IIS returns HTTP Error 404.3 - Not Found

In the "Physical Path" returned with the error is the correct file path, which when I copy-paste to Run opens the correct file.

Please let me know if this is possible.

like image 525
xander Avatar asked Nov 13 '13 10:11

xander


People also ask

Can a file have no extension?

What about files with no extension? Unlike the Macintosh which embeds creator information into files so they can have just about any name, a PC still mostly uses file extensions to associate programs with files. But, what do you do with a file that has no extension? The simple answer is: punt.

Which type of file type can be hosted through IIS?

IIS can even be configured to serve up ASP. NET-related files (i.e. dll's, . aspx and web. config files) which it would normally prevent from being downloaded – this takes some web.


1 Answers

Assuming (path) is a physical directory on your machine, create a new web.config file in that directory with the following content:

<?xml version="1.0" encoding="UTF-8"?>  <configuration>      <system.webServer>          <staticContent>              <mimeMap fileExtension="." mimeType="text/xml" />          </staticContent>      </system.webServer>  </configuration> 

You are telling IIS that for this directory only, any file without an otherwise defined extension (in MIME types) should be considered an xml file. Other file types in the same path should still work.

If you have the Windows feature IIS Management Scripts and Tools installed, you can use PowerShell to create such a web.config file:

Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Default Web Site/.well-known'  -filter "system.webServer/staticContent" -name "." -value @{fileExtension='.';mimeType='text/xml'} 

in this example Default Web Site is the name of the web site and .well-known is a directory under that site.

like image 176
Peter Hahndorf Avatar answered Sep 20 '22 17:09

Peter Hahndorf