首页 > 其他分享 >【App Service】在App Service中配置Virtual applications and directories,访问目录中的静态文件依旧报错404

【App Service】在App Service中配置Virtual applications and directories,访问目录中的静态文件依旧报错404

时间:2024-08-22 20:04:38浏览次数:5  
标签:文件 Service App 404 报错 location config

问题描述

在App Service Windows的环境中,想一个App Services下部署多个站点,比如/根目录下,从wwwroot中读取项目文件,而 /files 则通过配置的虚拟目录来读取 \mounts\sitefiles 目录中的静态文件。

在App Service的 Configuration Path Mapping 中配置如下:

通过Kudu查看App Service中的文件列表:

但是,在访问 /files/file1.html 时,出现404错误

问题解答

这个问题的根源在于Web.config的配置。因App Service for Windows环境使用IIS作为站点服务器。

如果在 Web.config 文件中,没有指定配置 location 节点,则所有请求都从wwwroot 下查找文件。

查看当前App Service的web.config文件内容,恰好缺少了location节点信息。

修改web.config,添加  <location path="." inheritInChildApplications="false">  .... ...   </location> 后,问题得到解决。

所以,正确的.net 应用部署到App Service后,web.config 的内容应参考下文(location节点不可缺少):

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\pfxDemo.dll" stdoutLogEnabled="false" stdoutLogFile="\\?\%home%\LogFiles\stdout" hostingModel="inprocess" />
    </system.webServer>
  </location>
</configuration>

 

参考资料

将 URL 路径映射到目录:https://docs.azure.cn/zh-cn/app-service/configure-common?tabs=portal#map-a-url-path-to-a-directory

Make application and directory-specific configuration settings in an ASP.NET application : https://learn.microsoft.com/zh-cn/troubleshoot/developer/webapps/aspnet/development/application-directory-configuration

 

标签:文件,Service,App,404,报错,location,config
From: https://www.cnblogs.com/lulight/p/18374639

相关文章