我正在将文件保存到Azure应用服务中wwwroot中的临时文件夹中。
但是当我尝试打开或获取文件时,它说找不到文件。如果我在本地服务器下的计算机上对其进行测试,则它可以工作。它不能在Azure App Services上运行吗?
是因为它是.msg文件吗?
答案 0 :(得分:0)
对Web应用程序文件的访问受基础Web服务器限制,因此不是因为扩展名。您可以通过在应用程序根目录中创建一个{。{3}}中的内容的web.config文件来启用对目录的匿名访问:
<?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>
由于您可能不想允许目录内容列出,因此我从指南中找到的标签中更改了<directoryBrowse/>
标签。自然,{您的临时目录}相对于web.config文件。重新启动您的Web应用程序,您应该会很好。