How to use a Local Storage Resource

The Windows Azure Managed Library provides classes for accessing the local storage resource from within code that is running in a role instance.

You will just need to retrieve the full path of a named local storage, and then you can store any file you want. To retrieve the full path, you simple need this line of code:

RoleEnvironment.GetLocalResource("MainLocalStorage").RootPath

Create Local Storage on Cloud Services to store temporary files

On a cloud service, you can create a small local storage where you can save temporary files, yes I said temporary, because a local storage would not be guaranteed to be durable, for durable storage in Azure you should consider Azure SQL Database or Azure Storage (blob and tables). This reserved space could be useful to store custom error log files (nlog, log4net, …), for those files that are dynamically created by the application and you would like to cache it somewhere, and also for structured data files like database(sql ce, sqlite, …), but remember, just for volatile data.

You can create a local storage manually configuring the Service Definition configuration file, or through the visual studio user interface:

Open the Properties of the Web Role under the Cloud Service Project, go to Local Storage section, and click on “Add Local Storage”, name the storage, give a size, and save.

Create Local Storage

For more information about Local Storage Resources visit http://msdn.microsoft.com/en-us/library/windowsazure/ee758708.aspx

How to add a Windows Azure Cloud Service Project on an existing Web Project

You can accomplish this easy step just right-clicking on the Web Project and then select the menu entry “Add Windows Azure Cloud Service Project”

How to add a Windows Azure Cloud Service Project on an existing Web Project

How to know if your code is running on the Windows Azure compute emulator

To understand whether the role instance is running in the Windows Azure compute emulator, you simply need to check this static variable:

RoleEnvironment.IsEmulated

Namespace: Microsoft.WindowsAzure.ServiceRuntime
Assembly: Microsoft.WindowsAzure.ServiceRuntime (in Microsoft.WindowsAzure.ServiceRuntime.dll)

http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleenvironment.isemulated.aspx

How to know if your code is running in the Windows Azure environment

To understand whether the role instance is running in the Windows Azure environment you simply need to check this static variable:

RoleEnvironment.IsAvailable

Namespace: Microsoft.WindowsAzure.ServiceRuntime
Assembly: Microsoft.WindowsAzure.ServiceRuntime (in Microsoft.WindowsAzure.ServiceRuntime.dll)

http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleenvironment.isavailable.aspx

Adding a PaaS Cloud Service (Web, Woker Role) to a Virtual Network

A PaaS cloud service, web or worker role, can be added in a Virtual Network only by changing its service configuration file (ServiceConfiguration.Cloud.cscfg).

You need to add the NetworkConfiguration node just after the Role node as follow:

<?xml version="1.0" encoding="utf-16"?>
<ServiceConfiguration xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" serviceName="MyAzureApplication" osFamily="3" osVersion="*" schemaVersion="2013-03.2.0" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
    <Role name="MyMvcWebRole">
        <ConfigurationSettings>
            <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="DefaultEndpointsProtocol=https;AccountName=xxx;AccountKey=xxx" />
        </ConfigurationSettings>
        <Instances count="1" />
    </Role>
    <NetworkConfiguration>
        <VirtualNetworkSite name="myazure-vnet"/>
        <AddressAssignments>
            <InstanceAddress roleName="MyMvcWebRole">
                <Subnets>
                    <Subnet name="MainSubnet"/>
                </Subnets>
            </InstanceAddress>
        </AddressAssignments>
    </NetworkConfiguration>
</ServiceConfiguration>