Is is possible to browse an Azure App Service temp directory? - azure

I am using the Kudu Dashboard to browse the folder of my Azure App Service. Specifically, I am browsing the D:\local\Temp\ since that is supposed to be (as far as I understand) the folder used to store temporary files created by my web app. For reference, here is a screenshot of the Kudu dashboard:
You can see from the screenshot that there is a file called xyz.tmp, this file is a file that I created manually trough the Kudu dashboard.
All this is good, however, when I try to read the file from my web app by using code such as:
var fileContent = System.IO.File.ReadAllText(#"D:\local\Temp\xyz.tmp");
I get an error stating that the file can't be found.
So my question is, what is going on? Why do I get the error? Also, I noticed that when I create a file in the same App Service temp director using code such as:
var fn = System.IO.Path.GetTempFileName();
System.IO.File.WriteAllText(fn, "abc123");
and then I try browsing for the file using the Kudo dashboard I don't see it in the temp directory.
So essentially, it all seems to point to the temp folder being displayed by the Kudo dashboard not representing the real temp folder used by the App Service. So if that is not the case then how exactly are you supposed to be able to browser the App Service temp folder?
Thanks.

From https://github.com/projectkudu/kudu/wiki/Understanding-the-Azure-App-Service-file-system:
Another important note is that the Main site and the scm site do not share temp files. So if you write some files there from your site, you will not see them from Kudu Console (and vice versa). You can make them use the same temp space if you disable separation (via WEBSITE_DISABLE_SCM_SEPARATION). But note that this is a legacy flag, and its use is not recommended/supported.

Related

Azure Websites: "Home" on C or D drive?

I have created a new a new Azure Website (Code deployment) and noticed via the Kudu site, that the the files are now on C:\ instead of D:\, e.g. this is from the Kudu site:
Site folder: C:\home
Temp folder: C:\local\Temp\
A week ago I thought that all my stuff was located on D:\home etc.
I asked this, because we deploy a WebJob via the Zip-Deployment option and need to set an absolute path to our config file, which is now on the "wrong" drive.
Also the Kudu-documentation uses D: for all values.
Has this changed recently? It's not a major problem, but I want to understand why.
Even if the Kudu console takes you to C:\home, D:\home is still accessible and points to the same place but I recommend you to always use the environment variable %HOME% and avoid using absolute paths.
For example, if you plan to use Windows Containers on App Service in the feature, the %HOME% env var also points to C:\home
Additionally, if you use App Service on Azure Stack for example, the %HOME% env var will also point to C:\home

FTP Access to Temp Folder

Under Advanced Tools (Kudu) Environment, it says there is a Temp folder at D:\local\Temp.
From the console, I could create files in the Temp folder. Is there FTP access to this folder?
No, you cannot.
I just checked: after logging in with FTP you can see the same folders you can see with Kudu under Debug console. The TEMP folder is not part of this.
Unlike Persisted files, these files are not shared among site instances. Also, you cannot rely on them staying there. For instance, if you restart a web app, you'll find that all of these folders get reset to their original state.
[...snip...]
Another important note is that the Main site and the scm site do not share temp files. So if you write some files there from your site, you will not see them from Kudu Console (and vice versa). You can make them use the same temp space if you disable separation (via WEBSITE_DISABLE_SCM_SEPARATION). But note that this is a legacy flag, and its use is not recommended/supported.
Taken from Understanding the Azure App Service file system.
Of course you can access the TEMP folder programmatically.

Prevent Azure App Service from viewing backend configuration

I am working on a project that has us deploying to an Azure Web Site.
The code is overall working and now we are focusing more on security.
Right now we are having an issue that back end configuration files are visible with the direct URL.
Examples (Link won't work):
https://myapplication.azurewebsite.net/foldername/FileName.xml (this
file is in a folder that is contained within the root application)
https://myapplication.azurewebsite.net/vApp/FileName.css (this file
is a part of virtual application sub folder)
I have found this to be true with multiple extensions and locations.
Extensions like:
.css
.htm
.xml
.html
the list likely goes on
I understand that certain files are downloaded to the client side and that those can't be stopped. However backend XML files are something we don't pass to the client (especially if has connection strings).
I did read a similar article, Azure App Service Instrumentation Profiling?
However this didn't directly relate to my issue.
Any insight would extremely helpful.
Do not store sensitive information in flat files, especially under your site root. Even if you web.config it just right you're still one botched commit away from disaster.
Use Application Settings instead, that's what they're for.
https://learn.microsoft.com/en-us/azure/app-service-web/web-sites-configure

How to deploy application in windows azure with text file?

I have created a mvc4 application with text file. I write some data in a file "ddd.txt". I wrote such address at my PC: "#D://Project//ddd.txt" and it worked finely. However, when I deploy my website on "azurewebsites.net", then I should write another address.
It is very important text file for me. And I would like to read data from it.
What address of directory should I write in my application to work him on Windows Azure server?
I would try using App_Data (you can just add the directory if it doesn't exist in your project).
You could then load the file like this:
string path = HttpContext.Server.MapPath("~/App_Data/ddd.txt");
// load file here
The other option would be to store it in Blob storage, there is a good walkthough of the different features here: http://www.windowsazure.com/en-us/develop/net/how-to-guides/blob-storage/

Folder permissions in Azure web sites

Just getting my head around the new Azure web sites feature and hitting my first obstacle. I'm deploying a PHP site which writes cache data to the file system, but the app is throwing an error because the folder it wants to write to does not have write permission. Is it possible to set permissions on folders or is this a no-no?
I can probably work round this but would like to know if it's possible.
Folder permissions cannot be set/customized. This means whatever location your app writes to should be under your site root.
Your site can only write to locations under C:\DWASFiles\Sites\[siteName]\VirtualDirectory0 and to the %TEMP% folder.
Two caveats here:
Stuff can't be written directly under VirtualDirectory0, you have to create a subfolder under there and place your files in that subfolder
The %TEMP% folder really is temporary! If your site instance goes down for any reason and is brought back up somewhere else then everything in your %TEMP% folder will be gone. Use it only for files that really are temporary.
Is the folder that the app is trying to write to under the site's folder?
It's my understanding that folder permissions cannot be set/changed. But I haven't seen anything from Microsoft that definitively says "yes" or "no" to that.
It should be possible using webdeploy.
However I don't think there is a way do it without manually setting up the webdeploy package - as described in the post http://blogs.msdn.com/b/azureappgallery/archive/2013/04/03/set-file-folder-permissions-for-your-content-on-azure-website-using-web-deployable-package.aspx.

Resources