【Azure App Service】C#下制作的网站,所有网页本地测试运行无误,发布至Azure之后,包含CHART(图表)的网页打开报错,错误消息为 Runtime Error: Server Error in '/' Application
问题描述
C#下制作的网站,所有网页本地测试运行无误,发布至Azure之后,包含CHART(图表)的网页打开报错,错误消息为 Runtime Error: Server Error in '/' Application
调查方式
面对C#的黄页错误,最好的做法就是根据提示,关闭C#的自定义错误页面,显示出真正的错误消息。根据提示,在Web.config文件中的system.web节点中添加设置 <customErrors mode="Off"/>
方式有二:
一:进入kudu站点,修改web.config (https://<your web app name>.scm.chinacloudsites.cn/DebugConsole)
二:在源代码中修改web.config,然后重新部署。
再次访问站点,即可得到正在的异常消息:System.IO.DirectoryNotFoundException
Invalid temp images directory in chart handler configuration [c:\TempImageFiles\]. Please edit the web.config file. The CharImageHandler key, Dir value must point to a valid directory. The directory is required for temporary image storage when storage mode equals file system. |
根据错误消息,在本地调试时,应用有权限可以直接访问及操作C盘下的目录,而当部署到Azure App Service后,应用对C盘的操作是不可操作的。
解决方案
在web.config中修改ChartImageHandler中对dir路径的设置,修改为d:/home。 如修改前后的值为:
修改前ChartImageHandler值 | 修改后ChartImageHandler值 |
<add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TempImageFiles\;" /> | <add key="ChartImageHandler" value="storage=file;timeout=20;dir=d:\home\;"/> |
修改后,测试App Serice可以成功访问:
参考资料
File structure on azure: https://github.com/projectkudu/kudu/wiki/File-structure-on-azure
Understanding the Azure App Service file system: https://github.com/projectkudu/kudu/wiki/Understanding-the-Azure-App-Service-file-system
Persisted files
This is what you can view as your web site's files. They follow a structure described here. They are rooted in
%HOME%
directory. For App Service on Linux and Web app for Containers, persistent storage is rooted in/home
.These files are persistent, meaning that you can rely on them staying there until you do something to change them. Also, they are shared between all instances of your site (when you scale it up to multiple instances). Internally, the way this works is that they are stored in Azure Storage instead of living on the local file system.
当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?