IIS:如何提供没有扩展名的文件? [英] IIS: How to serve a file without extension?

查看:50
本文介绍了IIS:如何提供没有扩展名的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 8.1 上使用 IIS 8.我有一个 XML 文件,我需要通过 (servername)/(path)

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) 由其他人预定义,不包含扩展名.我尝试了删除 .xml 文件文件名的简单解决方案,但 IIS 返回 HTTP 错误 404.3 - 未找到

(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.

如果可行,请告诉我.

推荐答案

假设 (path) 是你机器上的一个物理目录,在该目录下创建一个新的 web.config 文件,内容如下:

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>

您告诉 IIS 仅对于此目录,任何没有以其他方式定义的扩展名(在 MIME 类型中)的文件都应被视为 xml 文件.同一路径中的其他文件类型应该仍然有效.

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.

如果您安装了 Windows 功能 IIS 管理脚本和工具,您可以使用 PowerShell 创建这样的 web.config 文件:

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'}

在本例中,Default Web Site 是网站的名称,.well-known 是该网站下的目录.

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

这篇关于IIS:如何提供没有扩展名的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆