We have a page developed and deployed to Azure app service with local cache enabled.
Through code we are creating a file and writing data to it in Azure Kudu /home/site/wwwroot/*** folders* . When we run the page, file is getting created and deleted instantly. when we browse file, it got created with required data and if I reload i m getting file not found error.
Could you please suggest a solution , how to persist this file inside kudu (any path) and keep updating based on requirement ?
Note: Same solutions working in dev environment. Only difference for prod is Local cache
Tried to provide /home, /home/local , /data folders but same issue. Since its successfully getting created, no error is shown to debug
When we run the page, file is getting created and deleted instantly. when we browse file, it got created with required data and if I reload i m getting file not found error.
The files might not immediately persist in the local file system. The local cache might automatically remove files, leading to a "file not found" error when trying to access the file shortly after creation.
Use the App Data folder provided by Azure App Service. This folder is persistent across deployments and scaling events.
string appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string filePath = Path.Combine(appDataFolder, "yourfile.txt");
// use the /tmp directory.
string filePath = Path.Combine(Path.GetTempPath(), "your_file_name.txt");
File.WriteAllText(filePath, "your_data");
Using the Environment.GetFolderPath
method you can get the App Data folder path.
You can also try writing the file to a different directory outside of the /home
directory. Use the /tmp
directory as shown in above code snippet it used for temporary files and should not be affected by the local cache.
If local cache causing issues and you don't need it for your application, then disabling it. By this no local caching is performed, and your files will be directly written to and read from the file system.