简体   繁体   中英

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. 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. That is, I don't want my web.config file or Views folder for example to be exposed.

Is there any way to do this without using a custom Controller or RouteHandler ?

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.

Following David Gunderson answer, here is my web.config that allow CDN folder:

  <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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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