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:


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


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="" xmlns:xsi="" serviceName="MyAzureApplication" osFamily="3" osVersion="*" schemaVersion="2013-03.2.0" xmlns="">
    <Role name="MyMvcWebRole">
            <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="DefaultEndpointsProtocol=https;AccountName=xxx;AccountKey=xxx" />
        <Instances count="1" />
        <VirtualNetworkSite name="myazure-vnet"/>
            <InstanceAddress roleName="MyMvcWebRole">
                    <Subnet name="MainSubnet"/>