【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 describedhere. 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.