I have an Asp.net website hosted on Azure. It has an upload excel file functionality so a Fileupload control is in play.
string fileToSave = ConfigurationManager.AppSettings["DirectoryLocation"] + FileUpload.FileName;
FileUpload.PostedFile.SaveAs(fileToSave);
This works fine in traditional IIS servers but in Azure I am not sure what path to give in for "ConfigurationManager.AppSettings["DirectoryLocation"]".
I have tried some shared location but looks like it cannot access those.
Please give me some direction.
In contrast to a web application that is hosted on a local IIS your application can run on several instances in Azure that you do not have control over. It even can be moved to another server under certain circumstances. So using a local file system folder is not an option. Instead, you have to use a store that you can access from all the instances.
Have a look at the following overview of Azure Storage under this link. Typically, you would store files in a Blob or a File Storage. On this site, you can also find some samples on how to access the storage from the cloud (and later on from an on-premise application that processes the data).
This code should work but I would recommend you to store files in blob storage. See https://azure.microsoft.com/fr-fr/documentation/articles/storage-dotnet-how-to-use-blobs/
Related
Q1: Where do you think is the right place to put a SQLite database file (database.sqlite) in Azure Web App file system? For example:
D:\home\data\database.sqlite
D:\home\site\database.sqlite
D:\home\site\wwwroot\database.sqlite
other?
Q2: What else should be taken into consideration in order to make sure that the database file won't be accessible to public users as well as not being accidentally overwritten during deployments or when the app is scaled up/down? (The Web App is configured for deployments from a Local Git Repository)
Q3: Where to learn more about the file system used in Azure App Service, the official source URL? E.g. how it's shared between multiple VMs within a single Web App, how does it work when the App is scaled up/down, what's the difference between D:\home (persistent) vs D:\local (non-persistent)...
Note that SQLite does not work in Azure Blob Storage, so that one is not an option. Please, don't suggest alternative storage solutions, this question is specifically about SQLite.
References
Appropriate Uses For SQLite
In a Web App, your app is deployed to d:\home\site\wwwroot. This is the area where you may write files. As an example, the ghost deployment writes its SQLite database to d:\home\site\wwwroot\content\data\ghost.db. (easy to see this, if you open up the kudu console via yourapp.scm.azurewebsites.net):
This file area is shared amongst your web app instances. Similar to an SMB file share, but specific to web apps (and different than Azure's File Service).
The content under wwwroot is durable, unless you delete your app service. Scaling up/down impacts the amount of space available. (I have no idea what happens if you scale down and the smaller size has less disk space than what you're consuming already).
I would say the best location would be app_data folder in the site/wwwroot folder. Create the folder if it doesn't exist.
Web Apps can connect to storage accounts so you can in fact use blob storage and connect that to your web app. So in terms of learning more about it then you need to be looking at the appropriate page of documentation.
In your Web App settings you can then select which storage account to use. You can find this under Settings > Data Connections where you can select Storage from the drop down box.
I have a asp.net web forms web site that uses many files from server disk, accept uploads, processing files on the server. All the files stored in the web server's disks.
I would like to move my site to azure web sites. But to do that i think we need to update site code to keep files in azure blobs and process from it. Right now we are not able to that. So can i move my web site to azure without using azure blobs? Is there any way i can move all my site and files to azure, keep and publish on azure but not on azure blobs?
Using Virtual Machine is not an option to us right now.
Every Azure App Service/Website comes with persisted storage, which is technically an Azure storage blob mapped to the local file system. However, your code need not be aware of that. The details are described to the File System section here.
If you can configure paths for your server files, this persisted storage should suffice.
In my Azure Web Site I have in my AppSettings section in Web.Config some references to files on my disk. When deployed to Azure those references doesn't count any more. I know that you can overwrite AppSettings in Web.Config in the Azure environtment. But what is the file structure there?
A couple of examples from my web.config that I have to solve:
<add key="DataMapPath" value="d:\inetpub\MyWebApp\App_Data\map.xml"/>
<add key="CuteWebUI.AjaxUploader.TempDirectory" value="C:\Temp\WebApp\Attachments\UploaderTemp"/>
The first file tells our code to look for the map.xml-file in the App_Data-directory.
The last one tells our upload-controll where to upload files. I maybe should have used Azure Blob Storage here instead but that would need some major refactoring of our code.
Is there som best practices on this topic?
Our WebApp is running in production today, but I want to try out MS Azure. But I doesn't want to do to many code changes to make it work in Azure.
I have also read you can spin up an Virtual Machine (Windows Server) but that is overkill for my needs right now. We may go that way in the end, but for this testing-purpose it should be made simple.
Any suggestions on how this could be solved? Someone done this before? I guess someone has. Indeed.
If I do have read and write access to the file system for my Web Site I maybe could use this:
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TheFolder");
This would be appropriate for both on-premise and Azure deployment. But then I have to do some changes in our code.
You have multiple options:
Option 1: Use the App Settings of your web app to set custom settings for your website.
Option 2: Create multiple versions of your web.config (Visual Studio supports this) and deploy different versions to Azure and your local machine
Option 3: Make your path's relative to the paths of Azure Web App's environment variables
There's a HOME environment variable in your Azure Web App that resolves to the equivalent of inetpub for your site. Your app data folder is located at %HOME%\site\wwwroot\AppData.
There's also a TEMP environment both on Azure Web Apps and on your local machine. You can make your second setting relative to the TEMP environment variable value.
Actually you won't have this kind of "control" using azure web sites. To keep your app as it is, use Azure Virtual Machines.
A company provides me a .dll with many files.
The dll access to files using this kind of path "C:/folder/file.config".
I'm working on IIS 8 over a dedicated server BUT I would like to migrate the project on Windows Azure.
I know that Windows Azure provides Virtual Machines, But I wouldn't use it just for this need.
In my dream, I would like to use a web site linked to an Azure Storage and the dll which is located on the web site could access to its "C:/folder/file.config".
Could Windows Azure has a storage which support basic path ? ("C:/folder/file.config")
How could I solved this problem without using a Virtual Machine ?
You need to exercise caution before moving onto this Azure solution for the following reasons:
Azure Web Roles will have read/write access only to the Root Website folder and sub-folders. Not to any other.
Also, even if you manage to get permissions to the expected folder, remember that the instance can be recycled anytime. Meaning you need to repeat your startup task of creating the folder structure and putting the file there, setting up permissions etc.
And finally, the web instances are independent of each other with their own copies of the config file. So you need to take care of any sync issues. (just read-only doesn't pose a problem)
Filesystem access requires a bunch of csdef configurations as well along with elevated tasks.
http://blog.codingoutloud.com/2011/06/12/azure-faq-can-i-write-to-the-file-system-on-windows-azure/
In Azure Websites your website located here :
d:\home\site\wwwroot
which actually mapping for :
C:\DWASFiles\Sites\[your website name]
you can't access any parent folder above that folder in C: partition in Azure Websites
How do you access local files from within a windows azure web service? I tried routing the complete path to the file within VS but it says that access is denied. I was hoping there was something similar to Server.MapPath() in ASP.NET but I haven't come accross anything like that yet. Also I am running VS in Administrator mode. Any ideas?
NOTE: I am using a WCF Service (A cloud project in VS)
Things are different in Azure. Basically you need to indicate and set up local storage usage in the service definition file for your role. There is Local Storage section in the role properties. Once setup, you can access the local storage in your code by calling RoleEnvironment.GetLocalResource and passing in the local storage name. You can then read from and write to that local storage. Below are some blogposts on the topic.
Windows Azure Local File Storage - How To Guide and Warnings
Learning Azure Local Storage with me