Saturday, October 1, 2016

Configuring site settings using Azure PowerShell

To specify site settings using Azure PowerShell, use the Set-AzureWebsite cmdlet. 
For example,this code demonstrates enabling web sockets for a site.

$wsName = "contoso-web"
Set-AzureWebsite $wsName -WebSocketsEnabled $true


To define application settings using PowerShell, you will need to create a hashtable to define the setting. This is an example showing how to define a key/value pair for application settings.

$settings = New-Object Hashtable
$settings["Contoso_HR_WebService_URL"] = "https://contoso-webservices/hr"
Set-AzureWebsite $wsName -AppSettings $settings


This is an example of how to define a connection string using Azure PowerShell where a Connection String Info structure is used to deine the connection string.

$connStrs = (@{Name="contosodb"; Type="SQLAzure"; ConnectionString="Server=tcp:.." })
Set-AzureWebsite -Name $wsName -ConnectionStrings $connStrs

Configuring site settings using the management portal

There is a configuration section that contains a Site Settings icon in the Website blade for the Azure Website. Clicking this icon opens the Site Settings blade where you can make configuration changes.






Just about any website will have a database for storing data. Azure Websites has a unique way of configuring connection strings to the database by enabling you to provide a connection string setting as part of the website environment. By storing a connection string as a site setting,the application can retrieve the connection string at runtime as an environment variable
rather than storing it in a Web.conig or Php.ini ile. This approach is more secure because it avoids storing sensitive information, such as user id and password, in the coniguration files for the site. Azure Websites support the following types of database connection strings:

SQL Database A connection string for an Azure SQL Database.
SQL Server A connection string for a SQL Server running on a physical machine or perhaps an Azure Virtual Machine.
MySQL A connection string for a MySQL Database.
Custom A connection string for other NoSQL storage options, such as an Azure Storage account.

Azure Websites uses this same technique for application settings that a website may depend on. Application settings can be anything, such as a URL to a web service the application may depend on, or a custom runtime setting that the application code understands.

Site settings for connection strings and application settings are deined as key/value pairs. The key can be any name you want and is how you will reference the application setting and/or connection string. For example, the following is a sample of how a key/value pair could be deined for a connection string to a SQL database.


Key = "ContosoDBConnStr"Value = "Server=tcp:contosodbsrv01.database.windows.net,1433;Database=contoso-database;User ID=AdminUser@contosodbsrv01;Password={your_password_here};Trusted_Connection=False;Encrypt=True;Connection Timeout=30;"

The value for a connection string deined as a site setting can be retrieved at runtime by referencing the name of the environment variable for the setting. The name of the environment variable is a combination of a constant string based on the type of database connection string plus the name of the key. The constant strings are as follows:

■ SQLAZURECONNSTR_
■ SQLCONNSTR_
■ MYSQLCONNSTR_
■ CUSTOMCONNSTR_

Using the example from earlier, the environment variable name for the ContosoDBConnStr connection string is SQLAZURECONNSTR_ContosoDBConnStr.Similarly, the value for an application setting deined as a site setting can also be retrieved
at runtime by referencing the name of the environment variable for the setting. The constant string for application settings is APPSETTING_. As an example, if an application setting key is denied as ContosoHRWebServiceURL, then the environment variable name for the setting is APPSETTING_ ContosoHRWebServiceURL



NOTE :: 

SETTING CONNECTION STRINGS AND APPLICATION SETTINGS
Although it's not a requirement to store connection strings and application settings as site settings for an Azure website, it's recommended to do so. Application developers still have the option of storing these settings in application configuration files such as Web.config or Php.ini files.

If an application setting, or connection string, is denied in both an application configuration file and as a site setting in the Azure website, the site setting value takes precedence over the setting in the application configuration file.



Conigure Azure websites

With Azure Websites, you have many choices when it comes to website configuration settings and the tools you use to configure the website.

  • Configure site settings
  • Configure custom domains
  • Configure SSL certificates
  • Configure Microsoft Azure Traffic Manager
  • Configure handler mappings
  • Configure virtual applications and directories
  • Use the Azure Cross-Platform Command-Line Interface tools for configuration tasks

Featured Posts

Adding Accesspolicy to KeyVault for Service Principal Using Portal and Powershell

  Scripts path : https://drive.google.com/drive/folders/1sbBpnVFgXhUIXLdf2E9heyWDeU2f9427?usp=sharing  Adding Accesspolicy to KeyVault for S...