我正在将文件保存到Azure应用服务中wwwroot的临时文件夹中。
但是,当我尝试打开或获取文件时,它说找不到文件。如果我在本地服务器下的机器上对其进行测试,则可以正常工作。它不能在Azure应用服务上运行吗?
是否因为它是.msg文件?
对Web应用程序文件的访问受基础Web服务器限制,因此不是由于扩展名引起的。您可以通过在应用程序根目录中创建一个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应用程序,您应该一切顺利。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句