简体   繁体   English

配置IIS或Web.config以仅提供特定文件夹中的所有文件

[英]Config IIS or Web.config to serve all files in a specific folder only

I am developing a CDN server that is a normal MVC project. 我正在开发CDN服务器,它是一个普通的MVC项目。 However, in the project folder, suppose I have CDN folder, and I want everyone are allowed to access any files in there, with any file extension, and for CDN folder only. 但是,在项目文件夹中,假设我有CDN文件夹,并且希望所有人都可以访问其中具有任何扩展名的任何文件,并且仅适用于CDN文件夹。 That is, I don't want my web.config file or Views folder for example to be exposed. 也就是说,我不想公开我的web.config文件或Views文件夹。

Is there any way to do this without using a custom Controller or RouteHandler ? 没有使用自定义ControllerRouteHandler方法,有什么方法吗?

EDIT: As specified I am looking for a way in IIS or Web.config or somewhere else of writing code in Controller or RouteHandler, so it is not a duplicate. 编辑:正如指定的那样,我正在IIS或Web.config或在Controller或RouteHandler中编写代码的其他地方寻找方法,因此它不是重复的。

Following David Gunderson answer, here is my web.config that allow CDN folder: 在David Gunderson回答之后,这是我的允许CDN文件夹的web.config:

  <location path="CDN">
    <system.webServer>
      <staticContent>
        <mimeMap fileExtension="*" mimeType="application/octet-stream"/>
      </staticContent>
    </system.webServer>
  </location>

You can configure location settings for specific sub directories of your site in your web config: 您可以在Web配置中为站点的特定子目录配置位置设置:

https://msdn.microsoft.com/en-us/library/ms178692%28v=vs.140%29.aspx https://msdn.microsoft.com/en-us/library/ms178692%28v=vs.140%29.aspx

The following would grant all users access to the contents of the CDN folder if placed in your root web.config. 如果将以下内容放置在根web.config中,则将授予所有用户访问CDN文件夹内容的权限。 It will grant access to anonymous users even if you have forms authentication turned on for the rest of your site: 即使您为网站的其余部分启用了表单身份验证,它也会向匿名用户授予访问权限:

    <location path="CDN">
        <system.web>
            <authorization>
                <allow users="*"/>
            </authorization>
        </system.web>
    </location>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM