2
votes

I am saving a file into a temp folder in my wwwroot, in my Azure App Service.

But when I try to open or fetch the file, it says file not found. If I test it on my machine under a localhost server, it works. It won't work on the Azure App Services?

Is it because it is a .msg file?

FileZilla Snippet & Web page result

1

1 Answers

1
votes

Access to your Web App's files are restricted by the underlying web server, so it's not because of the extension. You can enable anonymous access to a directory by creating a web.config file in your application root with a content found in this guide:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
   <location path="{your-temp-directory}" allowOverride="false">
      <system.webServer>
         <directoryBrowse enabled="false"/>
         <defaultDocument>
            <files>
               <!-- When requesting a file listing, don't serve up the default 
               index.html file if it exists. -->
               <clear />
            </files>
         </defaultDocument>
         <security>
            <authorization>
               <!-- Allow all users access to the Public folder -->
               <remove users="*" roles="" verbs="" />
               <add accessType="Allow" users="*" roles="" />
            </authorization>
            <!-- Unblock all sourcecode related extensions (.cs, .aspx, .mdf)
             and files/folders (web.config, \bin) -->
            <requestFiltering>
               <hiddenSegments>
                  <clear />
               </hiddenSegments>
               <fileExtensions>
                  <clear />
               </fileExtensions>
            </requestFiltering>
         </security>
         <!-- Remove all ASP.NET file extension associations.
           Only include this if you have the ASP.NET feature installed, 
           otherwise this produces an Invalid configuration error. -->
         <handlers>
            <clear />
            <add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" />
         </handlers>
         <!-- Map all extensions to the same MIME type, so all files can be
           downloaded. -->
         <staticContent>
            <clear />
            <mimeMap fileExtension="*" mimeType="application/octet-stream" />
         </staticContent>
      </system.webServer>
   </location>
</configuration>

I've changed <directoryBrowse/> tag from the one found in the guide since you probably don't want to allow directory content listing. Naturally {your-temp-directory} is relative to the web.config file. Restart your Web App, and you should be good to go.