How to access files from within a cloud web service? - c#

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

Related

Need to access a directory from .net website hosted on Azure

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/

Moving an asp.net web forms site on azure without coding it again to use azure blob storage

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.

How to make file references to local disk work in Azure Web Site?

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.

Access to a specific file location (c:/folder/file) in an Azure website

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

Accessing the file system from a WCF service hosted in IIS

I have the need to read and write files on the server file system from within a WCF service hosted in IIS. This service is called via a Silverlight 4 application and RIA services. The file paths can be fixed to a known location on the server but we are having issues getting passed security issues and continue to get "Access Denied" errors. The application itself uses Forms Authentication and the web server is configured for anonymous access.
We haven't gotten passed this issue in our development environment and I'm assuming that in production we can specify a specific account in IIS to host the site under and then grant that account specific rights to the file system. In development using the VS 2010 development web server what are our options?
Our goal is to do something as simple as creating new files or deleting files from a known path on the server (i.e. "C:\Temp\") from within a method call to the WCF service. it's acceptable that it even be a temp folder underneath the virtual directory.
Your best option here: don't use the dev server for this; use IIS. Fighting tooling issues in something unrelated to what you are trying to do is a waste of time, so try to mimic your deployment environment as closely as possible.
You might also be able to use IISExpress for this, but since you know you already have nuances, I'd just go the whole-hog and use IIS. This also lets you hone the deployment process, which is a dev task.
Once setup, just create an app-pool and associate it with new account (not your account, unless it is going to be your account in production).

Categories

Resources