Sohail Ahmed
Sohail Ahmed

Reputation: 1190

How to use IIS for directory browsing for dynamic files?

I need to use IIS only for directory browsing. The directory contains ASP.NET Core files and IIS automatically attempts to serve them normally.

Is there a way to force IIS to display all files as static files?

Upvotes: 1

Views: 2040

Answers (1)

Cyril Durand
Cyril Durand

Reputation: 16192

In order to let IIS serves everything as static content, you have to

  1. Keep only Static Files handlers
  2. enable directory browsing
  3. Add mime type for every file. Without that IIS won't know how to serve unknown file type
  4. Disable request filtering to download .config file, bin folder content, etc.

You will find below the corresponding web.config

WARNING : big security issue. Be sure to understand the risk before applying this configuration

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <clear />
            <add name="StaticFiles" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" />
        </handlers>
        <directoryBrowse enabled="true" />
        <staticContent>
            <mimeMap fileExtension=".*" mimeType="application/octet-stream" />
        </staticContent>
        <security>
            <requestFiltering>
                <hiddenSegments>
                    <clear />
                </hiddenSegments>
                <fileExtensions>
                    <clear />
                </fileExtensions>
            </requestFiltering>
        </security>
    </system.webServer>
</configuration>

Upvotes: 1

Related Questions